github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/organizations/policyAttachment.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 organizations 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 // Provides a resource to attach an AWS Organizations policy to an organization account, root, or unit. 16 // 17 // ## Example Usage 18 // 19 // ### Organization Account 20 // 21 // <!--Start PulumiCodeChooser --> 22 // ```go 23 // package main 24 // 25 // import ( 26 // 27 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/organizations" 28 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 29 // 30 // ) 31 // 32 // func main() { 33 // pulumi.Run(func(ctx *pulumi.Context) error { 34 // _, err := organizations.NewPolicyAttachment(ctx, "account", &organizations.PolicyAttachmentArgs{ 35 // PolicyId: pulumi.Any(example.Id), 36 // TargetId: pulumi.String("123456789012"), 37 // }) 38 // if err != nil { 39 // return err 40 // } 41 // return nil 42 // }) 43 // } 44 // 45 // ``` 46 // <!--End PulumiCodeChooser --> 47 // 48 // ### Organization Root 49 // 50 // <!--Start PulumiCodeChooser --> 51 // ```go 52 // package main 53 // 54 // import ( 55 // 56 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/organizations" 57 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 58 // 59 // ) 60 // 61 // func main() { 62 // pulumi.Run(func(ctx *pulumi.Context) error { 63 // _, err := organizations.NewPolicyAttachment(ctx, "root", &organizations.PolicyAttachmentArgs{ 64 // PolicyId: pulumi.Any(example.Id), 65 // TargetId: pulumi.Any(exampleAwsOrganizationsOrganization.Roots[0].Id), 66 // }) 67 // if err != nil { 68 // return err 69 // } 70 // return nil 71 // }) 72 // } 73 // 74 // ``` 75 // <!--End PulumiCodeChooser --> 76 // 77 // ### Organization Unit 78 // 79 // <!--Start PulumiCodeChooser --> 80 // ```go 81 // package main 82 // 83 // import ( 84 // 85 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/organizations" 86 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 87 // 88 // ) 89 // 90 // func main() { 91 // pulumi.Run(func(ctx *pulumi.Context) error { 92 // _, err := organizations.NewPolicyAttachment(ctx, "unit", &organizations.PolicyAttachmentArgs{ 93 // PolicyId: pulumi.Any(example.Id), 94 // TargetId: pulumi.Any(exampleAwsOrganizationsOrganizationalUnit.Id), 95 // }) 96 // if err != nil { 97 // return err 98 // } 99 // return nil 100 // }) 101 // } 102 // 103 // ``` 104 // <!--End PulumiCodeChooser --> 105 // 106 // ## Import 107 // 108 // Using `pulumi import`, import `aws_organizations_policy_attachment` using the target ID and policy ID. For example: 109 // 110 // With an account target: 111 // 112 // ```sh 113 // $ pulumi import aws:organizations/policyAttachment:PolicyAttachment account 123456789012:p-12345678 114 // ``` 115 type PolicyAttachment struct { 116 pulumi.CustomResourceState 117 118 // The unique identifier (ID) of the policy that you want to attach to the target. 119 PolicyId pulumi.StringOutput `pulumi:"policyId"` 120 // If set to `true`, destroy will **not** detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy. 121 SkipDestroy pulumi.BoolPtrOutput `pulumi:"skipDestroy"` 122 // The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to. 123 TargetId pulumi.StringOutput `pulumi:"targetId"` 124 } 125 126 // NewPolicyAttachment registers a new resource with the given unique name, arguments, and options. 127 func NewPolicyAttachment(ctx *pulumi.Context, 128 name string, args *PolicyAttachmentArgs, opts ...pulumi.ResourceOption) (*PolicyAttachment, error) { 129 if args == nil { 130 return nil, errors.New("missing one or more required arguments") 131 } 132 133 if args.PolicyId == nil { 134 return nil, errors.New("invalid value for required argument 'PolicyId'") 135 } 136 if args.TargetId == nil { 137 return nil, errors.New("invalid value for required argument 'TargetId'") 138 } 139 opts = internal.PkgResourceDefaultOpts(opts) 140 var resource PolicyAttachment 141 err := ctx.RegisterResource("aws:organizations/policyAttachment:PolicyAttachment", name, args, &resource, opts...) 142 if err != nil { 143 return nil, err 144 } 145 return &resource, nil 146 } 147 148 // GetPolicyAttachment gets an existing PolicyAttachment resource's state with the given name, ID, and optional 149 // state properties that are used to uniquely qualify the lookup (nil if not required). 150 func GetPolicyAttachment(ctx *pulumi.Context, 151 name string, id pulumi.IDInput, state *PolicyAttachmentState, opts ...pulumi.ResourceOption) (*PolicyAttachment, error) { 152 var resource PolicyAttachment 153 err := ctx.ReadResource("aws:organizations/policyAttachment:PolicyAttachment", name, id, state, &resource, opts...) 154 if err != nil { 155 return nil, err 156 } 157 return &resource, nil 158 } 159 160 // Input properties used for looking up and filtering PolicyAttachment resources. 161 type policyAttachmentState struct { 162 // The unique identifier (ID) of the policy that you want to attach to the target. 163 PolicyId *string `pulumi:"policyId"` 164 // If set to `true`, destroy will **not** detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy. 165 SkipDestroy *bool `pulumi:"skipDestroy"` 166 // The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to. 167 TargetId *string `pulumi:"targetId"` 168 } 169 170 type PolicyAttachmentState struct { 171 // The unique identifier (ID) of the policy that you want to attach to the target. 172 PolicyId pulumi.StringPtrInput 173 // If set to `true`, destroy will **not** detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy. 174 SkipDestroy pulumi.BoolPtrInput 175 // The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to. 176 TargetId pulumi.StringPtrInput 177 } 178 179 func (PolicyAttachmentState) ElementType() reflect.Type { 180 return reflect.TypeOf((*policyAttachmentState)(nil)).Elem() 181 } 182 183 type policyAttachmentArgs struct { 184 // The unique identifier (ID) of the policy that you want to attach to the target. 185 PolicyId string `pulumi:"policyId"` 186 // If set to `true`, destroy will **not** detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy. 187 SkipDestroy *bool `pulumi:"skipDestroy"` 188 // The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to. 189 TargetId string `pulumi:"targetId"` 190 } 191 192 // The set of arguments for constructing a PolicyAttachment resource. 193 type PolicyAttachmentArgs struct { 194 // The unique identifier (ID) of the policy that you want to attach to the target. 195 PolicyId pulumi.StringInput 196 // If set to `true`, destroy will **not** detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy. 197 SkipDestroy pulumi.BoolPtrInput 198 // The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to. 199 TargetId pulumi.StringInput 200 } 201 202 func (PolicyAttachmentArgs) ElementType() reflect.Type { 203 return reflect.TypeOf((*policyAttachmentArgs)(nil)).Elem() 204 } 205 206 type PolicyAttachmentInput interface { 207 pulumi.Input 208 209 ToPolicyAttachmentOutput() PolicyAttachmentOutput 210 ToPolicyAttachmentOutputWithContext(ctx context.Context) PolicyAttachmentOutput 211 } 212 213 func (*PolicyAttachment) ElementType() reflect.Type { 214 return reflect.TypeOf((**PolicyAttachment)(nil)).Elem() 215 } 216 217 func (i *PolicyAttachment) ToPolicyAttachmentOutput() PolicyAttachmentOutput { 218 return i.ToPolicyAttachmentOutputWithContext(context.Background()) 219 } 220 221 func (i *PolicyAttachment) ToPolicyAttachmentOutputWithContext(ctx context.Context) PolicyAttachmentOutput { 222 return pulumi.ToOutputWithContext(ctx, i).(PolicyAttachmentOutput) 223 } 224 225 // PolicyAttachmentArrayInput is an input type that accepts PolicyAttachmentArray and PolicyAttachmentArrayOutput values. 226 // You can construct a concrete instance of `PolicyAttachmentArrayInput` via: 227 // 228 // PolicyAttachmentArray{ PolicyAttachmentArgs{...} } 229 type PolicyAttachmentArrayInput interface { 230 pulumi.Input 231 232 ToPolicyAttachmentArrayOutput() PolicyAttachmentArrayOutput 233 ToPolicyAttachmentArrayOutputWithContext(context.Context) PolicyAttachmentArrayOutput 234 } 235 236 type PolicyAttachmentArray []PolicyAttachmentInput 237 238 func (PolicyAttachmentArray) ElementType() reflect.Type { 239 return reflect.TypeOf((*[]*PolicyAttachment)(nil)).Elem() 240 } 241 242 func (i PolicyAttachmentArray) ToPolicyAttachmentArrayOutput() PolicyAttachmentArrayOutput { 243 return i.ToPolicyAttachmentArrayOutputWithContext(context.Background()) 244 } 245 246 func (i PolicyAttachmentArray) ToPolicyAttachmentArrayOutputWithContext(ctx context.Context) PolicyAttachmentArrayOutput { 247 return pulumi.ToOutputWithContext(ctx, i).(PolicyAttachmentArrayOutput) 248 } 249 250 // PolicyAttachmentMapInput is an input type that accepts PolicyAttachmentMap and PolicyAttachmentMapOutput values. 251 // You can construct a concrete instance of `PolicyAttachmentMapInput` via: 252 // 253 // PolicyAttachmentMap{ "key": PolicyAttachmentArgs{...} } 254 type PolicyAttachmentMapInput interface { 255 pulumi.Input 256 257 ToPolicyAttachmentMapOutput() PolicyAttachmentMapOutput 258 ToPolicyAttachmentMapOutputWithContext(context.Context) PolicyAttachmentMapOutput 259 } 260 261 type PolicyAttachmentMap map[string]PolicyAttachmentInput 262 263 func (PolicyAttachmentMap) ElementType() reflect.Type { 264 return reflect.TypeOf((*map[string]*PolicyAttachment)(nil)).Elem() 265 } 266 267 func (i PolicyAttachmentMap) ToPolicyAttachmentMapOutput() PolicyAttachmentMapOutput { 268 return i.ToPolicyAttachmentMapOutputWithContext(context.Background()) 269 } 270 271 func (i PolicyAttachmentMap) ToPolicyAttachmentMapOutputWithContext(ctx context.Context) PolicyAttachmentMapOutput { 272 return pulumi.ToOutputWithContext(ctx, i).(PolicyAttachmentMapOutput) 273 } 274 275 type PolicyAttachmentOutput struct{ *pulumi.OutputState } 276 277 func (PolicyAttachmentOutput) ElementType() reflect.Type { 278 return reflect.TypeOf((**PolicyAttachment)(nil)).Elem() 279 } 280 281 func (o PolicyAttachmentOutput) ToPolicyAttachmentOutput() PolicyAttachmentOutput { 282 return o 283 } 284 285 func (o PolicyAttachmentOutput) ToPolicyAttachmentOutputWithContext(ctx context.Context) PolicyAttachmentOutput { 286 return o 287 } 288 289 // The unique identifier (ID) of the policy that you want to attach to the target. 290 func (o PolicyAttachmentOutput) PolicyId() pulumi.StringOutput { 291 return o.ApplyT(func(v *PolicyAttachment) pulumi.StringOutput { return v.PolicyId }).(pulumi.StringOutput) 292 } 293 294 // If set to `true`, destroy will **not** detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy. 295 func (o PolicyAttachmentOutput) SkipDestroy() pulumi.BoolPtrOutput { 296 return o.ApplyT(func(v *PolicyAttachment) pulumi.BoolPtrOutput { return v.SkipDestroy }).(pulumi.BoolPtrOutput) 297 } 298 299 // The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to. 300 func (o PolicyAttachmentOutput) TargetId() pulumi.StringOutput { 301 return o.ApplyT(func(v *PolicyAttachment) pulumi.StringOutput { return v.TargetId }).(pulumi.StringOutput) 302 } 303 304 type PolicyAttachmentArrayOutput struct{ *pulumi.OutputState } 305 306 func (PolicyAttachmentArrayOutput) ElementType() reflect.Type { 307 return reflect.TypeOf((*[]*PolicyAttachment)(nil)).Elem() 308 } 309 310 func (o PolicyAttachmentArrayOutput) ToPolicyAttachmentArrayOutput() PolicyAttachmentArrayOutput { 311 return o 312 } 313 314 func (o PolicyAttachmentArrayOutput) ToPolicyAttachmentArrayOutputWithContext(ctx context.Context) PolicyAttachmentArrayOutput { 315 return o 316 } 317 318 func (o PolicyAttachmentArrayOutput) Index(i pulumi.IntInput) PolicyAttachmentOutput { 319 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *PolicyAttachment { 320 return vs[0].([]*PolicyAttachment)[vs[1].(int)] 321 }).(PolicyAttachmentOutput) 322 } 323 324 type PolicyAttachmentMapOutput struct{ *pulumi.OutputState } 325 326 func (PolicyAttachmentMapOutput) ElementType() reflect.Type { 327 return reflect.TypeOf((*map[string]*PolicyAttachment)(nil)).Elem() 328 } 329 330 func (o PolicyAttachmentMapOutput) ToPolicyAttachmentMapOutput() PolicyAttachmentMapOutput { 331 return o 332 } 333 334 func (o PolicyAttachmentMapOutput) ToPolicyAttachmentMapOutputWithContext(ctx context.Context) PolicyAttachmentMapOutput { 335 return o 336 } 337 338 func (o PolicyAttachmentMapOutput) MapIndex(k pulumi.StringInput) PolicyAttachmentOutput { 339 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *PolicyAttachment { 340 return vs[0].(map[string]*PolicyAttachment)[vs[1].(string)] 341 }).(PolicyAttachmentOutput) 342 } 343 344 func init() { 345 pulumi.RegisterInputType(reflect.TypeOf((*PolicyAttachmentInput)(nil)).Elem(), &PolicyAttachment{}) 346 pulumi.RegisterInputType(reflect.TypeOf((*PolicyAttachmentArrayInput)(nil)).Elem(), PolicyAttachmentArray{}) 347 pulumi.RegisterInputType(reflect.TypeOf((*PolicyAttachmentMapInput)(nil)).Elem(), PolicyAttachmentMap{}) 348 pulumi.RegisterOutputType(PolicyAttachmentOutput{}) 349 pulumi.RegisterOutputType(PolicyAttachmentArrayOutput{}) 350 pulumi.RegisterOutputType(PolicyAttachmentMapOutput{}) 351 }