github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iam/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 iam 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 // ## Example Usage 16 // 17 // <!--Start PulumiCodeChooser --> 18 // ```go 19 // package main 20 // 21 // import ( 22 // 23 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam" 24 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 25 // 26 // ) 27 // 28 // func main() { 29 // pulumi.Run(func(ctx *pulumi.Context) error { 30 // user, err := iam.NewUser(ctx, "user", &iam.UserArgs{ 31 // Name: pulumi.String("test-user"), 32 // }) 33 // if err != nil { 34 // return err 35 // } 36 // assumeRole, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{ 37 // Statements: []iam.GetPolicyDocumentStatement{ 38 // { 39 // Effect: pulumi.StringRef("Allow"), 40 // Principals: []iam.GetPolicyDocumentStatementPrincipal{ 41 // { 42 // Type: "Service", 43 // Identifiers: []string{ 44 // "ec2.amazonaws.com", 45 // }, 46 // }, 47 // }, 48 // Actions: []string{ 49 // "sts:AssumeRole", 50 // }, 51 // }, 52 // }, 53 // }, nil) 54 // if err != nil { 55 // return err 56 // } 57 // role, err := iam.NewRole(ctx, "role", &iam.RoleArgs{ 58 // Name: pulumi.String("test-role"), 59 // AssumeRolePolicy: pulumi.String(assumeRole.Json), 60 // }) 61 // if err != nil { 62 // return err 63 // } 64 // group, err := iam.NewGroup(ctx, "group", &iam.GroupArgs{ 65 // Name: pulumi.String("test-group"), 66 // }) 67 // if err != nil { 68 // return err 69 // } 70 // policy, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{ 71 // Statements: []iam.GetPolicyDocumentStatement{ 72 // { 73 // Effect: pulumi.StringRef("Allow"), 74 // Actions: []string{ 75 // "ec2:Describe*", 76 // }, 77 // Resources: []string{ 78 // "*", 79 // }, 80 // }, 81 // }, 82 // }, nil) 83 // if err != nil { 84 // return err 85 // } 86 // policyPolicy, err := iam.NewPolicy(ctx, "policy", &iam.PolicyArgs{ 87 // Name: pulumi.String("test-policy"), 88 // Description: pulumi.String("A test policy"), 89 // Policy: pulumi.String(policy.Json), 90 // }) 91 // if err != nil { 92 // return err 93 // } 94 // _, err = iam.NewPolicyAttachment(ctx, "test-attach", &iam.PolicyAttachmentArgs{ 95 // Name: pulumi.String("test-attachment"), 96 // Users: pulumi.Array{ 97 // user.Name, 98 // }, 99 // Roles: pulumi.Array{ 100 // role.Name, 101 // }, 102 // Groups: pulumi.Array{ 103 // group.Name, 104 // }, 105 // PolicyArn: policyPolicy.Arn, 106 // }) 107 // if err != nil { 108 // return err 109 // } 110 // return nil 111 // }) 112 // } 113 // 114 // ``` 115 // <!--End PulumiCodeChooser --> 116 type PolicyAttachment struct { 117 pulumi.CustomResourceState 118 119 // Group(s) the policy should be applied to. 120 Groups pulumi.StringArrayOutput `pulumi:"groups"` 121 // Name of the attachment. This cannot be an empty string. 122 Name pulumi.StringOutput `pulumi:"name"` 123 // ARN of the policy you want to apply. Typically this should be a reference to the ARN of another resource to ensure dependency ordering, such as `aws_iam_policy.example.arn`. 124 PolicyArn pulumi.StringOutput `pulumi:"policyArn"` 125 // Role(s) the policy should be applied to. 126 Roles pulumi.StringArrayOutput `pulumi:"roles"` 127 // User(s) the policy should be applied to. 128 Users pulumi.StringArrayOutput `pulumi:"users"` 129 } 130 131 // NewPolicyAttachment registers a new resource with the given unique name, arguments, and options. 132 func NewPolicyAttachment(ctx *pulumi.Context, 133 name string, args *PolicyAttachmentArgs, opts ...pulumi.ResourceOption) (*PolicyAttachment, error) { 134 if args == nil { 135 return nil, errors.New("missing one or more required arguments") 136 } 137 138 if args.PolicyArn == nil { 139 return nil, errors.New("invalid value for required argument 'PolicyArn'") 140 } 141 opts = internal.PkgResourceDefaultOpts(opts) 142 var resource PolicyAttachment 143 err := ctx.RegisterResource("aws:iam/policyAttachment:PolicyAttachment", name, args, &resource, opts...) 144 if err != nil { 145 return nil, err 146 } 147 return &resource, nil 148 } 149 150 // GetPolicyAttachment gets an existing PolicyAttachment resource's state with the given name, ID, and optional 151 // state properties that are used to uniquely qualify the lookup (nil if not required). 152 func GetPolicyAttachment(ctx *pulumi.Context, 153 name string, id pulumi.IDInput, state *PolicyAttachmentState, opts ...pulumi.ResourceOption) (*PolicyAttachment, error) { 154 var resource PolicyAttachment 155 err := ctx.ReadResource("aws:iam/policyAttachment:PolicyAttachment", name, id, state, &resource, opts...) 156 if err != nil { 157 return nil, err 158 } 159 return &resource, nil 160 } 161 162 // Input properties used for looking up and filtering PolicyAttachment resources. 163 type policyAttachmentState struct { 164 // Group(s) the policy should be applied to. 165 Groups []interface{} `pulumi:"groups"` 166 // Name of the attachment. This cannot be an empty string. 167 Name *string `pulumi:"name"` 168 // ARN of the policy you want to apply. Typically this should be a reference to the ARN of another resource to ensure dependency ordering, such as `aws_iam_policy.example.arn`. 169 PolicyArn *string `pulumi:"policyArn"` 170 // Role(s) the policy should be applied to. 171 Roles []interface{} `pulumi:"roles"` 172 // User(s) the policy should be applied to. 173 Users []interface{} `pulumi:"users"` 174 } 175 176 type PolicyAttachmentState struct { 177 // Group(s) the policy should be applied to. 178 Groups pulumi.ArrayInput 179 // Name of the attachment. This cannot be an empty string. 180 Name pulumi.StringPtrInput 181 // ARN of the policy you want to apply. Typically this should be a reference to the ARN of another resource to ensure dependency ordering, such as `aws_iam_policy.example.arn`. 182 PolicyArn pulumi.StringPtrInput 183 // Role(s) the policy should be applied to. 184 Roles pulumi.ArrayInput 185 // User(s) the policy should be applied to. 186 Users pulumi.ArrayInput 187 } 188 189 func (PolicyAttachmentState) ElementType() reflect.Type { 190 return reflect.TypeOf((*policyAttachmentState)(nil)).Elem() 191 } 192 193 type policyAttachmentArgs struct { 194 // Group(s) the policy should be applied to. 195 Groups []interface{} `pulumi:"groups"` 196 // Name of the attachment. This cannot be an empty string. 197 Name *string `pulumi:"name"` 198 // ARN of the policy you want to apply. Typically this should be a reference to the ARN of another resource to ensure dependency ordering, such as `aws_iam_policy.example.arn`. 199 PolicyArn string `pulumi:"policyArn"` 200 // Role(s) the policy should be applied to. 201 Roles []interface{} `pulumi:"roles"` 202 // User(s) the policy should be applied to. 203 Users []interface{} `pulumi:"users"` 204 } 205 206 // The set of arguments for constructing a PolicyAttachment resource. 207 type PolicyAttachmentArgs struct { 208 // Group(s) the policy should be applied to. 209 Groups pulumi.ArrayInput 210 // Name of the attachment. This cannot be an empty string. 211 Name pulumi.StringPtrInput 212 // ARN of the policy you want to apply. Typically this should be a reference to the ARN of another resource to ensure dependency ordering, such as `aws_iam_policy.example.arn`. 213 PolicyArn pulumi.StringInput 214 // Role(s) the policy should be applied to. 215 Roles pulumi.ArrayInput 216 // User(s) the policy should be applied to. 217 Users pulumi.ArrayInput 218 } 219 220 func (PolicyAttachmentArgs) ElementType() reflect.Type { 221 return reflect.TypeOf((*policyAttachmentArgs)(nil)).Elem() 222 } 223 224 type PolicyAttachmentInput interface { 225 pulumi.Input 226 227 ToPolicyAttachmentOutput() PolicyAttachmentOutput 228 ToPolicyAttachmentOutputWithContext(ctx context.Context) PolicyAttachmentOutput 229 } 230 231 func (*PolicyAttachment) ElementType() reflect.Type { 232 return reflect.TypeOf((**PolicyAttachment)(nil)).Elem() 233 } 234 235 func (i *PolicyAttachment) ToPolicyAttachmentOutput() PolicyAttachmentOutput { 236 return i.ToPolicyAttachmentOutputWithContext(context.Background()) 237 } 238 239 func (i *PolicyAttachment) ToPolicyAttachmentOutputWithContext(ctx context.Context) PolicyAttachmentOutput { 240 return pulumi.ToOutputWithContext(ctx, i).(PolicyAttachmentOutput) 241 } 242 243 // PolicyAttachmentArrayInput is an input type that accepts PolicyAttachmentArray and PolicyAttachmentArrayOutput values. 244 // You can construct a concrete instance of `PolicyAttachmentArrayInput` via: 245 // 246 // PolicyAttachmentArray{ PolicyAttachmentArgs{...} } 247 type PolicyAttachmentArrayInput interface { 248 pulumi.Input 249 250 ToPolicyAttachmentArrayOutput() PolicyAttachmentArrayOutput 251 ToPolicyAttachmentArrayOutputWithContext(context.Context) PolicyAttachmentArrayOutput 252 } 253 254 type PolicyAttachmentArray []PolicyAttachmentInput 255 256 func (PolicyAttachmentArray) ElementType() reflect.Type { 257 return reflect.TypeOf((*[]*PolicyAttachment)(nil)).Elem() 258 } 259 260 func (i PolicyAttachmentArray) ToPolicyAttachmentArrayOutput() PolicyAttachmentArrayOutput { 261 return i.ToPolicyAttachmentArrayOutputWithContext(context.Background()) 262 } 263 264 func (i PolicyAttachmentArray) ToPolicyAttachmentArrayOutputWithContext(ctx context.Context) PolicyAttachmentArrayOutput { 265 return pulumi.ToOutputWithContext(ctx, i).(PolicyAttachmentArrayOutput) 266 } 267 268 // PolicyAttachmentMapInput is an input type that accepts PolicyAttachmentMap and PolicyAttachmentMapOutput values. 269 // You can construct a concrete instance of `PolicyAttachmentMapInput` via: 270 // 271 // PolicyAttachmentMap{ "key": PolicyAttachmentArgs{...} } 272 type PolicyAttachmentMapInput interface { 273 pulumi.Input 274 275 ToPolicyAttachmentMapOutput() PolicyAttachmentMapOutput 276 ToPolicyAttachmentMapOutputWithContext(context.Context) PolicyAttachmentMapOutput 277 } 278 279 type PolicyAttachmentMap map[string]PolicyAttachmentInput 280 281 func (PolicyAttachmentMap) ElementType() reflect.Type { 282 return reflect.TypeOf((*map[string]*PolicyAttachment)(nil)).Elem() 283 } 284 285 func (i PolicyAttachmentMap) ToPolicyAttachmentMapOutput() PolicyAttachmentMapOutput { 286 return i.ToPolicyAttachmentMapOutputWithContext(context.Background()) 287 } 288 289 func (i PolicyAttachmentMap) ToPolicyAttachmentMapOutputWithContext(ctx context.Context) PolicyAttachmentMapOutput { 290 return pulumi.ToOutputWithContext(ctx, i).(PolicyAttachmentMapOutput) 291 } 292 293 type PolicyAttachmentOutput struct{ *pulumi.OutputState } 294 295 func (PolicyAttachmentOutput) ElementType() reflect.Type { 296 return reflect.TypeOf((**PolicyAttachment)(nil)).Elem() 297 } 298 299 func (o PolicyAttachmentOutput) ToPolicyAttachmentOutput() PolicyAttachmentOutput { 300 return o 301 } 302 303 func (o PolicyAttachmentOutput) ToPolicyAttachmentOutputWithContext(ctx context.Context) PolicyAttachmentOutput { 304 return o 305 } 306 307 // Group(s) the policy should be applied to. 308 func (o PolicyAttachmentOutput) Groups() pulumi.StringArrayOutput { 309 return o.ApplyT(func(v *PolicyAttachment) pulumi.StringArrayOutput { return v.Groups }).(pulumi.StringArrayOutput) 310 } 311 312 // Name of the attachment. This cannot be an empty string. 313 func (o PolicyAttachmentOutput) Name() pulumi.StringOutput { 314 return o.ApplyT(func(v *PolicyAttachment) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput) 315 } 316 317 // ARN of the policy you want to apply. Typically this should be a reference to the ARN of another resource to ensure dependency ordering, such as `aws_iam_policy.example.arn`. 318 func (o PolicyAttachmentOutput) PolicyArn() pulumi.StringOutput { 319 return o.ApplyT(func(v *PolicyAttachment) pulumi.StringOutput { return v.PolicyArn }).(pulumi.StringOutput) 320 } 321 322 // Role(s) the policy should be applied to. 323 func (o PolicyAttachmentOutput) Roles() pulumi.StringArrayOutput { 324 return o.ApplyT(func(v *PolicyAttachment) pulumi.StringArrayOutput { return v.Roles }).(pulumi.StringArrayOutput) 325 } 326 327 // User(s) the policy should be applied to. 328 func (o PolicyAttachmentOutput) Users() pulumi.StringArrayOutput { 329 return o.ApplyT(func(v *PolicyAttachment) pulumi.StringArrayOutput { return v.Users }).(pulumi.StringArrayOutput) 330 } 331 332 type PolicyAttachmentArrayOutput struct{ *pulumi.OutputState } 333 334 func (PolicyAttachmentArrayOutput) ElementType() reflect.Type { 335 return reflect.TypeOf((*[]*PolicyAttachment)(nil)).Elem() 336 } 337 338 func (o PolicyAttachmentArrayOutput) ToPolicyAttachmentArrayOutput() PolicyAttachmentArrayOutput { 339 return o 340 } 341 342 func (o PolicyAttachmentArrayOutput) ToPolicyAttachmentArrayOutputWithContext(ctx context.Context) PolicyAttachmentArrayOutput { 343 return o 344 } 345 346 func (o PolicyAttachmentArrayOutput) Index(i pulumi.IntInput) PolicyAttachmentOutput { 347 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *PolicyAttachment { 348 return vs[0].([]*PolicyAttachment)[vs[1].(int)] 349 }).(PolicyAttachmentOutput) 350 } 351 352 type PolicyAttachmentMapOutput struct{ *pulumi.OutputState } 353 354 func (PolicyAttachmentMapOutput) ElementType() reflect.Type { 355 return reflect.TypeOf((*map[string]*PolicyAttachment)(nil)).Elem() 356 } 357 358 func (o PolicyAttachmentMapOutput) ToPolicyAttachmentMapOutput() PolicyAttachmentMapOutput { 359 return o 360 } 361 362 func (o PolicyAttachmentMapOutput) ToPolicyAttachmentMapOutputWithContext(ctx context.Context) PolicyAttachmentMapOutput { 363 return o 364 } 365 366 func (o PolicyAttachmentMapOutput) MapIndex(k pulumi.StringInput) PolicyAttachmentOutput { 367 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *PolicyAttachment { 368 return vs[0].(map[string]*PolicyAttachment)[vs[1].(string)] 369 }).(PolicyAttachmentOutput) 370 } 371 372 func init() { 373 pulumi.RegisterInputType(reflect.TypeOf((*PolicyAttachmentInput)(nil)).Elem(), &PolicyAttachment{}) 374 pulumi.RegisterInputType(reflect.TypeOf((*PolicyAttachmentArrayInput)(nil)).Elem(), PolicyAttachmentArray{}) 375 pulumi.RegisterInputType(reflect.TypeOf((*PolicyAttachmentMapInput)(nil)).Elem(), PolicyAttachmentMap{}) 376 pulumi.RegisterOutputType(PolicyAttachmentOutput{}) 377 pulumi.RegisterOutputType(PolicyAttachmentArrayOutput{}) 378 pulumi.RegisterOutputType(PolicyAttachmentMapOutput{}) 379 }