github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/kms/keyPolicy.go (about) 1 // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT. 2 // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! *** 3 4 package kms 5 6 import ( 7 "context" 8 "reflect" 9 10 "errors" 11 "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal" 12 "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 13 ) 14 15 // Attaches a policy to a KMS Key. 16 // 17 // ## Example Usage 18 // 19 // <!--Start PulumiCodeChooser --> 20 // ```go 21 // package main 22 // 23 // import ( 24 // 25 // "encoding/json" 26 // 27 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/kms" 28 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 29 // 30 // ) 31 // 32 // func main() { 33 // pulumi.Run(func(ctx *pulumi.Context) error { 34 // example, err := kms.NewKey(ctx, "example", &kms.KeyArgs{ 35 // Description: pulumi.String("example"), 36 // }) 37 // if err != nil { 38 // return err 39 // } 40 // tmpJSON0, err := json.Marshal(map[string]interface{}{ 41 // "Id": "example", 42 // "Statement": []map[string]interface{}{ 43 // map[string]interface{}{ 44 // "Action": "kms:*", 45 // "Effect": "Allow", 46 // "Principal": map[string]interface{}{ 47 // "AWS": "*", 48 // }, 49 // "Resource": "*", 50 // "Sid": "Enable IAM User Permissions", 51 // }, 52 // }, 53 // "Version": "2012-10-17", 54 // }) 55 // if err != nil { 56 // return err 57 // } 58 // json0 := string(tmpJSON0) 59 // _, err = kms.NewKeyPolicy(ctx, "example", &kms.KeyPolicyArgs{ 60 // KeyId: example.ID(), 61 // Policy: pulumi.String(json0), 62 // }) 63 // if err != nil { 64 // return err 65 // } 66 // return nil 67 // }) 68 // } 69 // 70 // ``` 71 // <!--End PulumiCodeChooser --> 72 // 73 // ## Import 74 // 75 // Using `pulumi import`, import KMS Key Policies using the `key_id`. For example: 76 // 77 // ```sh 78 // $ pulumi import aws:kms/keyPolicy:KeyPolicy a 1234abcd-12ab-34cd-56ef-1234567890ab 79 // ``` 80 type KeyPolicy struct { 81 pulumi.CustomResourceState 82 83 // A flag to indicate whether to bypass the key policy lockout safety check. 84 // Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. 85 // For more information, refer to the scenario in the [Default Key Policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default-allow-root-enable-iam) section in the _AWS Key Management Service Developer Guide_. 86 BypassPolicyLockoutSafetyCheck pulumi.BoolPtrOutput `pulumi:"bypassPolicyLockoutSafetyCheck"` 87 // The ID of the KMS Key to attach the policy. 88 KeyId pulumi.StringOutput `pulumi:"keyId"` 89 // A valid policy JSON document. Although this is a key policy, not an IAM policy, an `iam.getPolicyDocument`, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide. 90 // 91 // > **NOTE:** Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a [default key policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default) that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants. 92 Policy pulumi.StringOutput `pulumi:"policy"` 93 } 94 95 // NewKeyPolicy registers a new resource with the given unique name, arguments, and options. 96 func NewKeyPolicy(ctx *pulumi.Context, 97 name string, args *KeyPolicyArgs, opts ...pulumi.ResourceOption) (*KeyPolicy, error) { 98 if args == nil { 99 return nil, errors.New("missing one or more required arguments") 100 } 101 102 if args.KeyId == nil { 103 return nil, errors.New("invalid value for required argument 'KeyId'") 104 } 105 if args.Policy == nil { 106 return nil, errors.New("invalid value for required argument 'Policy'") 107 } 108 opts = internal.PkgResourceDefaultOpts(opts) 109 var resource KeyPolicy 110 err := ctx.RegisterResource("aws:kms/keyPolicy:KeyPolicy", name, args, &resource, opts...) 111 if err != nil { 112 return nil, err 113 } 114 return &resource, nil 115 } 116 117 // GetKeyPolicy gets an existing KeyPolicy resource's state with the given name, ID, and optional 118 // state properties that are used to uniquely qualify the lookup (nil if not required). 119 func GetKeyPolicy(ctx *pulumi.Context, 120 name string, id pulumi.IDInput, state *KeyPolicyState, opts ...pulumi.ResourceOption) (*KeyPolicy, error) { 121 var resource KeyPolicy 122 err := ctx.ReadResource("aws:kms/keyPolicy:KeyPolicy", name, id, state, &resource, opts...) 123 if err != nil { 124 return nil, err 125 } 126 return &resource, nil 127 } 128 129 // Input properties used for looking up and filtering KeyPolicy resources. 130 type keyPolicyState struct { 131 // A flag to indicate whether to bypass the key policy lockout safety check. 132 // Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. 133 // For more information, refer to the scenario in the [Default Key Policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default-allow-root-enable-iam) section in the _AWS Key Management Service Developer Guide_. 134 BypassPolicyLockoutSafetyCheck *bool `pulumi:"bypassPolicyLockoutSafetyCheck"` 135 // The ID of the KMS Key to attach the policy. 136 KeyId *string `pulumi:"keyId"` 137 // A valid policy JSON document. Although this is a key policy, not an IAM policy, an `iam.getPolicyDocument`, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide. 138 // 139 // > **NOTE:** Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a [default key policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default) that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants. 140 Policy *string `pulumi:"policy"` 141 } 142 143 type KeyPolicyState struct { 144 // A flag to indicate whether to bypass the key policy lockout safety check. 145 // Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. 146 // For more information, refer to the scenario in the [Default Key Policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default-allow-root-enable-iam) section in the _AWS Key Management Service Developer Guide_. 147 BypassPolicyLockoutSafetyCheck pulumi.BoolPtrInput 148 // The ID of the KMS Key to attach the policy. 149 KeyId pulumi.StringPtrInput 150 // A valid policy JSON document. Although this is a key policy, not an IAM policy, an `iam.getPolicyDocument`, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide. 151 // 152 // > **NOTE:** Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a [default key policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default) that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants. 153 Policy pulumi.StringPtrInput 154 } 155 156 func (KeyPolicyState) ElementType() reflect.Type { 157 return reflect.TypeOf((*keyPolicyState)(nil)).Elem() 158 } 159 160 type keyPolicyArgs struct { 161 // A flag to indicate whether to bypass the key policy lockout safety check. 162 // Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. 163 // For more information, refer to the scenario in the [Default Key Policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default-allow-root-enable-iam) section in the _AWS Key Management Service Developer Guide_. 164 BypassPolicyLockoutSafetyCheck *bool `pulumi:"bypassPolicyLockoutSafetyCheck"` 165 // The ID of the KMS Key to attach the policy. 166 KeyId string `pulumi:"keyId"` 167 // A valid policy JSON document. Although this is a key policy, not an IAM policy, an `iam.getPolicyDocument`, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide. 168 // 169 // > **NOTE:** Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a [default key policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default) that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants. 170 Policy string `pulumi:"policy"` 171 } 172 173 // The set of arguments for constructing a KeyPolicy resource. 174 type KeyPolicyArgs struct { 175 // A flag to indicate whether to bypass the key policy lockout safety check. 176 // Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. 177 // For more information, refer to the scenario in the [Default Key Policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default-allow-root-enable-iam) section in the _AWS Key Management Service Developer Guide_. 178 BypassPolicyLockoutSafetyCheck pulumi.BoolPtrInput 179 // The ID of the KMS Key to attach the policy. 180 KeyId pulumi.StringInput 181 // A valid policy JSON document. Although this is a key policy, not an IAM policy, an `iam.getPolicyDocument`, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide. 182 // 183 // > **NOTE:** Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a [default key policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default) that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants. 184 Policy pulumi.StringInput 185 } 186 187 func (KeyPolicyArgs) ElementType() reflect.Type { 188 return reflect.TypeOf((*keyPolicyArgs)(nil)).Elem() 189 } 190 191 type KeyPolicyInput interface { 192 pulumi.Input 193 194 ToKeyPolicyOutput() KeyPolicyOutput 195 ToKeyPolicyOutputWithContext(ctx context.Context) KeyPolicyOutput 196 } 197 198 func (*KeyPolicy) ElementType() reflect.Type { 199 return reflect.TypeOf((**KeyPolicy)(nil)).Elem() 200 } 201 202 func (i *KeyPolicy) ToKeyPolicyOutput() KeyPolicyOutput { 203 return i.ToKeyPolicyOutputWithContext(context.Background()) 204 } 205 206 func (i *KeyPolicy) ToKeyPolicyOutputWithContext(ctx context.Context) KeyPolicyOutput { 207 return pulumi.ToOutputWithContext(ctx, i).(KeyPolicyOutput) 208 } 209 210 // KeyPolicyArrayInput is an input type that accepts KeyPolicyArray and KeyPolicyArrayOutput values. 211 // You can construct a concrete instance of `KeyPolicyArrayInput` via: 212 // 213 // KeyPolicyArray{ KeyPolicyArgs{...} } 214 type KeyPolicyArrayInput interface { 215 pulumi.Input 216 217 ToKeyPolicyArrayOutput() KeyPolicyArrayOutput 218 ToKeyPolicyArrayOutputWithContext(context.Context) KeyPolicyArrayOutput 219 } 220 221 type KeyPolicyArray []KeyPolicyInput 222 223 func (KeyPolicyArray) ElementType() reflect.Type { 224 return reflect.TypeOf((*[]*KeyPolicy)(nil)).Elem() 225 } 226 227 func (i KeyPolicyArray) ToKeyPolicyArrayOutput() KeyPolicyArrayOutput { 228 return i.ToKeyPolicyArrayOutputWithContext(context.Background()) 229 } 230 231 func (i KeyPolicyArray) ToKeyPolicyArrayOutputWithContext(ctx context.Context) KeyPolicyArrayOutput { 232 return pulumi.ToOutputWithContext(ctx, i).(KeyPolicyArrayOutput) 233 } 234 235 // KeyPolicyMapInput is an input type that accepts KeyPolicyMap and KeyPolicyMapOutput values. 236 // You can construct a concrete instance of `KeyPolicyMapInput` via: 237 // 238 // KeyPolicyMap{ "key": KeyPolicyArgs{...} } 239 type KeyPolicyMapInput interface { 240 pulumi.Input 241 242 ToKeyPolicyMapOutput() KeyPolicyMapOutput 243 ToKeyPolicyMapOutputWithContext(context.Context) KeyPolicyMapOutput 244 } 245 246 type KeyPolicyMap map[string]KeyPolicyInput 247 248 func (KeyPolicyMap) ElementType() reflect.Type { 249 return reflect.TypeOf((*map[string]*KeyPolicy)(nil)).Elem() 250 } 251 252 func (i KeyPolicyMap) ToKeyPolicyMapOutput() KeyPolicyMapOutput { 253 return i.ToKeyPolicyMapOutputWithContext(context.Background()) 254 } 255 256 func (i KeyPolicyMap) ToKeyPolicyMapOutputWithContext(ctx context.Context) KeyPolicyMapOutput { 257 return pulumi.ToOutputWithContext(ctx, i).(KeyPolicyMapOutput) 258 } 259 260 type KeyPolicyOutput struct{ *pulumi.OutputState } 261 262 func (KeyPolicyOutput) ElementType() reflect.Type { 263 return reflect.TypeOf((**KeyPolicy)(nil)).Elem() 264 } 265 266 func (o KeyPolicyOutput) ToKeyPolicyOutput() KeyPolicyOutput { 267 return o 268 } 269 270 func (o KeyPolicyOutput) ToKeyPolicyOutputWithContext(ctx context.Context) KeyPolicyOutput { 271 return o 272 } 273 274 // A flag to indicate whether to bypass the key policy lockout safety check. 275 // Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. 276 // For more information, refer to the scenario in the [Default Key Policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default-allow-root-enable-iam) section in the _AWS Key Management Service Developer Guide_. 277 func (o KeyPolicyOutput) BypassPolicyLockoutSafetyCheck() pulumi.BoolPtrOutput { 278 return o.ApplyT(func(v *KeyPolicy) pulumi.BoolPtrOutput { return v.BypassPolicyLockoutSafetyCheck }).(pulumi.BoolPtrOutput) 279 } 280 281 // The ID of the KMS Key to attach the policy. 282 func (o KeyPolicyOutput) KeyId() pulumi.StringOutput { 283 return o.ApplyT(func(v *KeyPolicy) pulumi.StringOutput { return v.KeyId }).(pulumi.StringOutput) 284 } 285 286 // A valid policy JSON document. Although this is a key policy, not an IAM policy, an `iam.getPolicyDocument`, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide. 287 // 288 // > **NOTE:** Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a [default key policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default) that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants. 289 func (o KeyPolicyOutput) Policy() pulumi.StringOutput { 290 return o.ApplyT(func(v *KeyPolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput) 291 } 292 293 type KeyPolicyArrayOutput struct{ *pulumi.OutputState } 294 295 func (KeyPolicyArrayOutput) ElementType() reflect.Type { 296 return reflect.TypeOf((*[]*KeyPolicy)(nil)).Elem() 297 } 298 299 func (o KeyPolicyArrayOutput) ToKeyPolicyArrayOutput() KeyPolicyArrayOutput { 300 return o 301 } 302 303 func (o KeyPolicyArrayOutput) ToKeyPolicyArrayOutputWithContext(ctx context.Context) KeyPolicyArrayOutput { 304 return o 305 } 306 307 func (o KeyPolicyArrayOutput) Index(i pulumi.IntInput) KeyPolicyOutput { 308 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *KeyPolicy { 309 return vs[0].([]*KeyPolicy)[vs[1].(int)] 310 }).(KeyPolicyOutput) 311 } 312 313 type KeyPolicyMapOutput struct{ *pulumi.OutputState } 314 315 func (KeyPolicyMapOutput) ElementType() reflect.Type { 316 return reflect.TypeOf((*map[string]*KeyPolicy)(nil)).Elem() 317 } 318 319 func (o KeyPolicyMapOutput) ToKeyPolicyMapOutput() KeyPolicyMapOutput { 320 return o 321 } 322 323 func (o KeyPolicyMapOutput) ToKeyPolicyMapOutputWithContext(ctx context.Context) KeyPolicyMapOutput { 324 return o 325 } 326 327 func (o KeyPolicyMapOutput) MapIndex(k pulumi.StringInput) KeyPolicyOutput { 328 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *KeyPolicy { 329 return vs[0].(map[string]*KeyPolicy)[vs[1].(string)] 330 }).(KeyPolicyOutput) 331 } 332 333 func init() { 334 pulumi.RegisterInputType(reflect.TypeOf((*KeyPolicyInput)(nil)).Elem(), &KeyPolicy{}) 335 pulumi.RegisterInputType(reflect.TypeOf((*KeyPolicyArrayInput)(nil)).Elem(), KeyPolicyArray{}) 336 pulumi.RegisterInputType(reflect.TypeOf((*KeyPolicyMapInput)(nil)).Elem(), KeyPolicyMap{}) 337 pulumi.RegisterOutputType(KeyPolicyOutput{}) 338 pulumi.RegisterOutputType(KeyPolicyArrayOutput{}) 339 pulumi.RegisterOutputType(KeyPolicyMapOutput{}) 340 }