github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iam/rolePolicyAttachment.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 // Attaches a Managed IAM Policy to an IAM role 16 // 17 // > **NOTE:** The usage of this resource conflicts with the `iam.PolicyAttachment` resource and will permanently show a difference if both are defined. 18 // 19 // > **NOTE:** For a given role, this resource is incompatible with using the `iam.Role` resource `managedPolicyArns` argument. When using that argument and this resource, both will attempt to manage the role's managed policy attachments and Pulumi will show a permanent difference. 20 // 21 // ## Example Usage 22 // 23 // <!--Start PulumiCodeChooser --> 24 // ```go 25 // package main 26 // 27 // import ( 28 // 29 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam" 30 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 31 // 32 // ) 33 // 34 // func main() { 35 // pulumi.Run(func(ctx *pulumi.Context) error { 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 // policy, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{ 65 // Statements: []iam.GetPolicyDocumentStatement{ 66 // { 67 // Effect: pulumi.StringRef("Allow"), 68 // Actions: []string{ 69 // "ec2:Describe*", 70 // }, 71 // Resources: []string{ 72 // "*", 73 // }, 74 // }, 75 // }, 76 // }, nil) 77 // if err != nil { 78 // return err 79 // } 80 // policyPolicy, err := iam.NewPolicy(ctx, "policy", &iam.PolicyArgs{ 81 // Name: pulumi.String("test-policy"), 82 // Description: pulumi.String("A test policy"), 83 // Policy: pulumi.String(policy.Json), 84 // }) 85 // if err != nil { 86 // return err 87 // } 88 // _, err = iam.NewRolePolicyAttachment(ctx, "test-attach", &iam.RolePolicyAttachmentArgs{ 89 // Role: role.Name, 90 // PolicyArn: policyPolicy.Arn, 91 // }) 92 // if err != nil { 93 // return err 94 // } 95 // return nil 96 // }) 97 // } 98 // 99 // ``` 100 // <!--End PulumiCodeChooser --> 101 // 102 // ## Import 103 // 104 // Using `pulumi import`, import IAM role policy attachments using the role name and policy arn separated by `/`. For example: 105 // 106 // ```sh 107 // $ pulumi import aws:iam/rolePolicyAttachment:RolePolicyAttachment test-attach test-role/arn:aws:iam::xxxxxxxxxxxx:policy/test-policy 108 // ``` 109 type RolePolicyAttachment struct { 110 pulumi.CustomResourceState 111 112 // The ARN of the policy you want to apply 113 PolicyArn pulumi.StringOutput `pulumi:"policyArn"` 114 // The name of the IAM role to which the policy should be applied 115 Role pulumi.StringOutput `pulumi:"role"` 116 } 117 118 // NewRolePolicyAttachment registers a new resource with the given unique name, arguments, and options. 119 func NewRolePolicyAttachment(ctx *pulumi.Context, 120 name string, args *RolePolicyAttachmentArgs, opts ...pulumi.ResourceOption) (*RolePolicyAttachment, error) { 121 if args == nil { 122 return nil, errors.New("missing one or more required arguments") 123 } 124 125 if args.PolicyArn == nil { 126 return nil, errors.New("invalid value for required argument 'PolicyArn'") 127 } 128 if args.Role == nil { 129 return nil, errors.New("invalid value for required argument 'Role'") 130 } 131 opts = internal.PkgResourceDefaultOpts(opts) 132 var resource RolePolicyAttachment 133 err := ctx.RegisterResource("aws:iam/rolePolicyAttachment:RolePolicyAttachment", name, args, &resource, opts...) 134 if err != nil { 135 return nil, err 136 } 137 return &resource, nil 138 } 139 140 // GetRolePolicyAttachment gets an existing RolePolicyAttachment resource's state with the given name, ID, and optional 141 // state properties that are used to uniquely qualify the lookup (nil if not required). 142 func GetRolePolicyAttachment(ctx *pulumi.Context, 143 name string, id pulumi.IDInput, state *RolePolicyAttachmentState, opts ...pulumi.ResourceOption) (*RolePolicyAttachment, error) { 144 var resource RolePolicyAttachment 145 err := ctx.ReadResource("aws:iam/rolePolicyAttachment:RolePolicyAttachment", name, id, state, &resource, opts...) 146 if err != nil { 147 return nil, err 148 } 149 return &resource, nil 150 } 151 152 // Input properties used for looking up and filtering RolePolicyAttachment resources. 153 type rolePolicyAttachmentState struct { 154 // The ARN of the policy you want to apply 155 PolicyArn *string `pulumi:"policyArn"` 156 // The name of the IAM role to which the policy should be applied 157 Role interface{} `pulumi:"role"` 158 } 159 160 type RolePolicyAttachmentState struct { 161 // The ARN of the policy you want to apply 162 PolicyArn pulumi.StringPtrInput 163 // The name of the IAM role to which the policy should be applied 164 Role pulumi.Input 165 } 166 167 func (RolePolicyAttachmentState) ElementType() reflect.Type { 168 return reflect.TypeOf((*rolePolicyAttachmentState)(nil)).Elem() 169 } 170 171 type rolePolicyAttachmentArgs struct { 172 // The ARN of the policy you want to apply 173 PolicyArn string `pulumi:"policyArn"` 174 // The name of the IAM role to which the policy should be applied 175 Role interface{} `pulumi:"role"` 176 } 177 178 // The set of arguments for constructing a RolePolicyAttachment resource. 179 type RolePolicyAttachmentArgs struct { 180 // The ARN of the policy you want to apply 181 PolicyArn pulumi.StringInput 182 // The name of the IAM role to which the policy should be applied 183 Role pulumi.Input 184 } 185 186 func (RolePolicyAttachmentArgs) ElementType() reflect.Type { 187 return reflect.TypeOf((*rolePolicyAttachmentArgs)(nil)).Elem() 188 } 189 190 type RolePolicyAttachmentInput interface { 191 pulumi.Input 192 193 ToRolePolicyAttachmentOutput() RolePolicyAttachmentOutput 194 ToRolePolicyAttachmentOutputWithContext(ctx context.Context) RolePolicyAttachmentOutput 195 } 196 197 func (*RolePolicyAttachment) ElementType() reflect.Type { 198 return reflect.TypeOf((**RolePolicyAttachment)(nil)).Elem() 199 } 200 201 func (i *RolePolicyAttachment) ToRolePolicyAttachmentOutput() RolePolicyAttachmentOutput { 202 return i.ToRolePolicyAttachmentOutputWithContext(context.Background()) 203 } 204 205 func (i *RolePolicyAttachment) ToRolePolicyAttachmentOutputWithContext(ctx context.Context) RolePolicyAttachmentOutput { 206 return pulumi.ToOutputWithContext(ctx, i).(RolePolicyAttachmentOutput) 207 } 208 209 // RolePolicyAttachmentArrayInput is an input type that accepts RolePolicyAttachmentArray and RolePolicyAttachmentArrayOutput values. 210 // You can construct a concrete instance of `RolePolicyAttachmentArrayInput` via: 211 // 212 // RolePolicyAttachmentArray{ RolePolicyAttachmentArgs{...} } 213 type RolePolicyAttachmentArrayInput interface { 214 pulumi.Input 215 216 ToRolePolicyAttachmentArrayOutput() RolePolicyAttachmentArrayOutput 217 ToRolePolicyAttachmentArrayOutputWithContext(context.Context) RolePolicyAttachmentArrayOutput 218 } 219 220 type RolePolicyAttachmentArray []RolePolicyAttachmentInput 221 222 func (RolePolicyAttachmentArray) ElementType() reflect.Type { 223 return reflect.TypeOf((*[]*RolePolicyAttachment)(nil)).Elem() 224 } 225 226 func (i RolePolicyAttachmentArray) ToRolePolicyAttachmentArrayOutput() RolePolicyAttachmentArrayOutput { 227 return i.ToRolePolicyAttachmentArrayOutputWithContext(context.Background()) 228 } 229 230 func (i RolePolicyAttachmentArray) ToRolePolicyAttachmentArrayOutputWithContext(ctx context.Context) RolePolicyAttachmentArrayOutput { 231 return pulumi.ToOutputWithContext(ctx, i).(RolePolicyAttachmentArrayOutput) 232 } 233 234 // RolePolicyAttachmentMapInput is an input type that accepts RolePolicyAttachmentMap and RolePolicyAttachmentMapOutput values. 235 // You can construct a concrete instance of `RolePolicyAttachmentMapInput` via: 236 // 237 // RolePolicyAttachmentMap{ "key": RolePolicyAttachmentArgs{...} } 238 type RolePolicyAttachmentMapInput interface { 239 pulumi.Input 240 241 ToRolePolicyAttachmentMapOutput() RolePolicyAttachmentMapOutput 242 ToRolePolicyAttachmentMapOutputWithContext(context.Context) RolePolicyAttachmentMapOutput 243 } 244 245 type RolePolicyAttachmentMap map[string]RolePolicyAttachmentInput 246 247 func (RolePolicyAttachmentMap) ElementType() reflect.Type { 248 return reflect.TypeOf((*map[string]*RolePolicyAttachment)(nil)).Elem() 249 } 250 251 func (i RolePolicyAttachmentMap) ToRolePolicyAttachmentMapOutput() RolePolicyAttachmentMapOutput { 252 return i.ToRolePolicyAttachmentMapOutputWithContext(context.Background()) 253 } 254 255 func (i RolePolicyAttachmentMap) ToRolePolicyAttachmentMapOutputWithContext(ctx context.Context) RolePolicyAttachmentMapOutput { 256 return pulumi.ToOutputWithContext(ctx, i).(RolePolicyAttachmentMapOutput) 257 } 258 259 type RolePolicyAttachmentOutput struct{ *pulumi.OutputState } 260 261 func (RolePolicyAttachmentOutput) ElementType() reflect.Type { 262 return reflect.TypeOf((**RolePolicyAttachment)(nil)).Elem() 263 } 264 265 func (o RolePolicyAttachmentOutput) ToRolePolicyAttachmentOutput() RolePolicyAttachmentOutput { 266 return o 267 } 268 269 func (o RolePolicyAttachmentOutput) ToRolePolicyAttachmentOutputWithContext(ctx context.Context) RolePolicyAttachmentOutput { 270 return o 271 } 272 273 // The ARN of the policy you want to apply 274 func (o RolePolicyAttachmentOutput) PolicyArn() pulumi.StringOutput { 275 return o.ApplyT(func(v *RolePolicyAttachment) pulumi.StringOutput { return v.PolicyArn }).(pulumi.StringOutput) 276 } 277 278 // The name of the IAM role to which the policy should be applied 279 func (o RolePolicyAttachmentOutput) Role() pulumi.StringOutput { 280 return o.ApplyT(func(v *RolePolicyAttachment) pulumi.StringOutput { return v.Role }).(pulumi.StringOutput) 281 } 282 283 type RolePolicyAttachmentArrayOutput struct{ *pulumi.OutputState } 284 285 func (RolePolicyAttachmentArrayOutput) ElementType() reflect.Type { 286 return reflect.TypeOf((*[]*RolePolicyAttachment)(nil)).Elem() 287 } 288 289 func (o RolePolicyAttachmentArrayOutput) ToRolePolicyAttachmentArrayOutput() RolePolicyAttachmentArrayOutput { 290 return o 291 } 292 293 func (o RolePolicyAttachmentArrayOutput) ToRolePolicyAttachmentArrayOutputWithContext(ctx context.Context) RolePolicyAttachmentArrayOutput { 294 return o 295 } 296 297 func (o RolePolicyAttachmentArrayOutput) Index(i pulumi.IntInput) RolePolicyAttachmentOutput { 298 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *RolePolicyAttachment { 299 return vs[0].([]*RolePolicyAttachment)[vs[1].(int)] 300 }).(RolePolicyAttachmentOutput) 301 } 302 303 type RolePolicyAttachmentMapOutput struct{ *pulumi.OutputState } 304 305 func (RolePolicyAttachmentMapOutput) ElementType() reflect.Type { 306 return reflect.TypeOf((*map[string]*RolePolicyAttachment)(nil)).Elem() 307 } 308 309 func (o RolePolicyAttachmentMapOutput) ToRolePolicyAttachmentMapOutput() RolePolicyAttachmentMapOutput { 310 return o 311 } 312 313 func (o RolePolicyAttachmentMapOutput) ToRolePolicyAttachmentMapOutputWithContext(ctx context.Context) RolePolicyAttachmentMapOutput { 314 return o 315 } 316 317 func (o RolePolicyAttachmentMapOutput) MapIndex(k pulumi.StringInput) RolePolicyAttachmentOutput { 318 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *RolePolicyAttachment { 319 return vs[0].(map[string]*RolePolicyAttachment)[vs[1].(string)] 320 }).(RolePolicyAttachmentOutput) 321 } 322 323 func init() { 324 pulumi.RegisterInputType(reflect.TypeOf((*RolePolicyAttachmentInput)(nil)).Elem(), &RolePolicyAttachment{}) 325 pulumi.RegisterInputType(reflect.TypeOf((*RolePolicyAttachmentArrayInput)(nil)).Elem(), RolePolicyAttachmentArray{}) 326 pulumi.RegisterInputType(reflect.TypeOf((*RolePolicyAttachmentMapInput)(nil)).Elem(), RolePolicyAttachmentMap{}) 327 pulumi.RegisterOutputType(RolePolicyAttachmentOutput{}) 328 pulumi.RegisterOutputType(RolePolicyAttachmentArrayOutput{}) 329 pulumi.RegisterOutputType(RolePolicyAttachmentMapOutput{}) 330 }