github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iam/userPolicyAttachment.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 user
    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  // ## Example Usage
    20  //
    21  // <!--Start PulumiCodeChooser -->
    22  // ```go
    23  // package main
    24  //
    25  // import (
    26  //
    27  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    28  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    29  //
    30  // )
    31  //
    32  //	func main() {
    33  //		pulumi.Run(func(ctx *pulumi.Context) error {
    34  //			user, err := iam.NewUser(ctx, "user", &iam.UserArgs{
    35  //				Name: pulumi.String("test-user"),
    36  //			})
    37  //			if err != nil {
    38  //				return err
    39  //			}
    40  //			policy, err := iam.NewPolicy(ctx, "policy", &iam.PolicyArgs{
    41  //				Name:        pulumi.String("test-policy"),
    42  //				Description: pulumi.String("A test policy"),
    43  //				Policy:      pulumi.Any("{ ... policy JSON ... }"),
    44  //			})
    45  //			if err != nil {
    46  //				return err
    47  //			}
    48  //			_, err = iam.NewUserPolicyAttachment(ctx, "test-attach", &iam.UserPolicyAttachmentArgs{
    49  //				User:      user.Name,
    50  //				PolicyArn: policy.Arn,
    51  //			})
    52  //			if err != nil {
    53  //				return err
    54  //			}
    55  //			return nil
    56  //		})
    57  //	}
    58  //
    59  // ```
    60  // <!--End PulumiCodeChooser -->
    61  //
    62  // ## Import
    63  //
    64  // Using `pulumi import`, import IAM user policy attachments using the user name and policy arn separated by `/`. For example:
    65  //
    66  // ```sh
    67  // $ pulumi import aws:iam/userPolicyAttachment:UserPolicyAttachment test-attach test-user/arn:aws:iam::xxxxxxxxxxxx:policy/test-policy
    68  // ```
    69  type UserPolicyAttachment struct {
    70  	pulumi.CustomResourceState
    71  
    72  	// The ARN of the policy you want to apply
    73  	PolicyArn pulumi.StringOutput `pulumi:"policyArn"`
    74  	// The user the policy should be applied to
    75  	User pulumi.StringOutput `pulumi:"user"`
    76  }
    77  
    78  // NewUserPolicyAttachment registers a new resource with the given unique name, arguments, and options.
    79  func NewUserPolicyAttachment(ctx *pulumi.Context,
    80  	name string, args *UserPolicyAttachmentArgs, opts ...pulumi.ResourceOption) (*UserPolicyAttachment, error) {
    81  	if args == nil {
    82  		return nil, errors.New("missing one or more required arguments")
    83  	}
    84  
    85  	if args.PolicyArn == nil {
    86  		return nil, errors.New("invalid value for required argument 'PolicyArn'")
    87  	}
    88  	if args.User == nil {
    89  		return nil, errors.New("invalid value for required argument 'User'")
    90  	}
    91  	opts = internal.PkgResourceDefaultOpts(opts)
    92  	var resource UserPolicyAttachment
    93  	err := ctx.RegisterResource("aws:iam/userPolicyAttachment:UserPolicyAttachment", name, args, &resource, opts...)
    94  	if err != nil {
    95  		return nil, err
    96  	}
    97  	return &resource, nil
    98  }
    99  
   100  // GetUserPolicyAttachment gets an existing UserPolicyAttachment resource's state with the given name, ID, and optional
   101  // state properties that are used to uniquely qualify the lookup (nil if not required).
   102  func GetUserPolicyAttachment(ctx *pulumi.Context,
   103  	name string, id pulumi.IDInput, state *UserPolicyAttachmentState, opts ...pulumi.ResourceOption) (*UserPolicyAttachment, error) {
   104  	var resource UserPolicyAttachment
   105  	err := ctx.ReadResource("aws:iam/userPolicyAttachment:UserPolicyAttachment", name, id, state, &resource, opts...)
   106  	if err != nil {
   107  		return nil, err
   108  	}
   109  	return &resource, nil
   110  }
   111  
   112  // Input properties used for looking up and filtering UserPolicyAttachment resources.
   113  type userPolicyAttachmentState struct {
   114  	// The ARN of the policy you want to apply
   115  	PolicyArn *string `pulumi:"policyArn"`
   116  	// The user the policy should be applied to
   117  	User interface{} `pulumi:"user"`
   118  }
   119  
   120  type UserPolicyAttachmentState struct {
   121  	// The ARN of the policy you want to apply
   122  	PolicyArn pulumi.StringPtrInput
   123  	// The user the policy should be applied to
   124  	User pulumi.Input
   125  }
   126  
   127  func (UserPolicyAttachmentState) ElementType() reflect.Type {
   128  	return reflect.TypeOf((*userPolicyAttachmentState)(nil)).Elem()
   129  }
   130  
   131  type userPolicyAttachmentArgs struct {
   132  	// The ARN of the policy you want to apply
   133  	PolicyArn string `pulumi:"policyArn"`
   134  	// The user the policy should be applied to
   135  	User interface{} `pulumi:"user"`
   136  }
   137  
   138  // The set of arguments for constructing a UserPolicyAttachment resource.
   139  type UserPolicyAttachmentArgs struct {
   140  	// The ARN of the policy you want to apply
   141  	PolicyArn pulumi.StringInput
   142  	// The user the policy should be applied to
   143  	User pulumi.Input
   144  }
   145  
   146  func (UserPolicyAttachmentArgs) ElementType() reflect.Type {
   147  	return reflect.TypeOf((*userPolicyAttachmentArgs)(nil)).Elem()
   148  }
   149  
   150  type UserPolicyAttachmentInput interface {
   151  	pulumi.Input
   152  
   153  	ToUserPolicyAttachmentOutput() UserPolicyAttachmentOutput
   154  	ToUserPolicyAttachmentOutputWithContext(ctx context.Context) UserPolicyAttachmentOutput
   155  }
   156  
   157  func (*UserPolicyAttachment) ElementType() reflect.Type {
   158  	return reflect.TypeOf((**UserPolicyAttachment)(nil)).Elem()
   159  }
   160  
   161  func (i *UserPolicyAttachment) ToUserPolicyAttachmentOutput() UserPolicyAttachmentOutput {
   162  	return i.ToUserPolicyAttachmentOutputWithContext(context.Background())
   163  }
   164  
   165  func (i *UserPolicyAttachment) ToUserPolicyAttachmentOutputWithContext(ctx context.Context) UserPolicyAttachmentOutput {
   166  	return pulumi.ToOutputWithContext(ctx, i).(UserPolicyAttachmentOutput)
   167  }
   168  
   169  // UserPolicyAttachmentArrayInput is an input type that accepts UserPolicyAttachmentArray and UserPolicyAttachmentArrayOutput values.
   170  // You can construct a concrete instance of `UserPolicyAttachmentArrayInput` via:
   171  //
   172  //	UserPolicyAttachmentArray{ UserPolicyAttachmentArgs{...} }
   173  type UserPolicyAttachmentArrayInput interface {
   174  	pulumi.Input
   175  
   176  	ToUserPolicyAttachmentArrayOutput() UserPolicyAttachmentArrayOutput
   177  	ToUserPolicyAttachmentArrayOutputWithContext(context.Context) UserPolicyAttachmentArrayOutput
   178  }
   179  
   180  type UserPolicyAttachmentArray []UserPolicyAttachmentInput
   181  
   182  func (UserPolicyAttachmentArray) ElementType() reflect.Type {
   183  	return reflect.TypeOf((*[]*UserPolicyAttachment)(nil)).Elem()
   184  }
   185  
   186  func (i UserPolicyAttachmentArray) ToUserPolicyAttachmentArrayOutput() UserPolicyAttachmentArrayOutput {
   187  	return i.ToUserPolicyAttachmentArrayOutputWithContext(context.Background())
   188  }
   189  
   190  func (i UserPolicyAttachmentArray) ToUserPolicyAttachmentArrayOutputWithContext(ctx context.Context) UserPolicyAttachmentArrayOutput {
   191  	return pulumi.ToOutputWithContext(ctx, i).(UserPolicyAttachmentArrayOutput)
   192  }
   193  
   194  // UserPolicyAttachmentMapInput is an input type that accepts UserPolicyAttachmentMap and UserPolicyAttachmentMapOutput values.
   195  // You can construct a concrete instance of `UserPolicyAttachmentMapInput` via:
   196  //
   197  //	UserPolicyAttachmentMap{ "key": UserPolicyAttachmentArgs{...} }
   198  type UserPolicyAttachmentMapInput interface {
   199  	pulumi.Input
   200  
   201  	ToUserPolicyAttachmentMapOutput() UserPolicyAttachmentMapOutput
   202  	ToUserPolicyAttachmentMapOutputWithContext(context.Context) UserPolicyAttachmentMapOutput
   203  }
   204  
   205  type UserPolicyAttachmentMap map[string]UserPolicyAttachmentInput
   206  
   207  func (UserPolicyAttachmentMap) ElementType() reflect.Type {
   208  	return reflect.TypeOf((*map[string]*UserPolicyAttachment)(nil)).Elem()
   209  }
   210  
   211  func (i UserPolicyAttachmentMap) ToUserPolicyAttachmentMapOutput() UserPolicyAttachmentMapOutput {
   212  	return i.ToUserPolicyAttachmentMapOutputWithContext(context.Background())
   213  }
   214  
   215  func (i UserPolicyAttachmentMap) ToUserPolicyAttachmentMapOutputWithContext(ctx context.Context) UserPolicyAttachmentMapOutput {
   216  	return pulumi.ToOutputWithContext(ctx, i).(UserPolicyAttachmentMapOutput)
   217  }
   218  
   219  type UserPolicyAttachmentOutput struct{ *pulumi.OutputState }
   220  
   221  func (UserPolicyAttachmentOutput) ElementType() reflect.Type {
   222  	return reflect.TypeOf((**UserPolicyAttachment)(nil)).Elem()
   223  }
   224  
   225  func (o UserPolicyAttachmentOutput) ToUserPolicyAttachmentOutput() UserPolicyAttachmentOutput {
   226  	return o
   227  }
   228  
   229  func (o UserPolicyAttachmentOutput) ToUserPolicyAttachmentOutputWithContext(ctx context.Context) UserPolicyAttachmentOutput {
   230  	return o
   231  }
   232  
   233  // The ARN of the policy you want to apply
   234  func (o UserPolicyAttachmentOutput) PolicyArn() pulumi.StringOutput {
   235  	return o.ApplyT(func(v *UserPolicyAttachment) pulumi.StringOutput { return v.PolicyArn }).(pulumi.StringOutput)
   236  }
   237  
   238  // The user the policy should be applied to
   239  func (o UserPolicyAttachmentOutput) User() pulumi.StringOutput {
   240  	return o.ApplyT(func(v *UserPolicyAttachment) pulumi.StringOutput { return v.User }).(pulumi.StringOutput)
   241  }
   242  
   243  type UserPolicyAttachmentArrayOutput struct{ *pulumi.OutputState }
   244  
   245  func (UserPolicyAttachmentArrayOutput) ElementType() reflect.Type {
   246  	return reflect.TypeOf((*[]*UserPolicyAttachment)(nil)).Elem()
   247  }
   248  
   249  func (o UserPolicyAttachmentArrayOutput) ToUserPolicyAttachmentArrayOutput() UserPolicyAttachmentArrayOutput {
   250  	return o
   251  }
   252  
   253  func (o UserPolicyAttachmentArrayOutput) ToUserPolicyAttachmentArrayOutputWithContext(ctx context.Context) UserPolicyAttachmentArrayOutput {
   254  	return o
   255  }
   256  
   257  func (o UserPolicyAttachmentArrayOutput) Index(i pulumi.IntInput) UserPolicyAttachmentOutput {
   258  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *UserPolicyAttachment {
   259  		return vs[0].([]*UserPolicyAttachment)[vs[1].(int)]
   260  	}).(UserPolicyAttachmentOutput)
   261  }
   262  
   263  type UserPolicyAttachmentMapOutput struct{ *pulumi.OutputState }
   264  
   265  func (UserPolicyAttachmentMapOutput) ElementType() reflect.Type {
   266  	return reflect.TypeOf((*map[string]*UserPolicyAttachment)(nil)).Elem()
   267  }
   268  
   269  func (o UserPolicyAttachmentMapOutput) ToUserPolicyAttachmentMapOutput() UserPolicyAttachmentMapOutput {
   270  	return o
   271  }
   272  
   273  func (o UserPolicyAttachmentMapOutput) ToUserPolicyAttachmentMapOutputWithContext(ctx context.Context) UserPolicyAttachmentMapOutput {
   274  	return o
   275  }
   276  
   277  func (o UserPolicyAttachmentMapOutput) MapIndex(k pulumi.StringInput) UserPolicyAttachmentOutput {
   278  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *UserPolicyAttachment {
   279  		return vs[0].(map[string]*UserPolicyAttachment)[vs[1].(string)]
   280  	}).(UserPolicyAttachmentOutput)
   281  }
   282  
   283  func init() {
   284  	pulumi.RegisterInputType(reflect.TypeOf((*UserPolicyAttachmentInput)(nil)).Elem(), &UserPolicyAttachment{})
   285  	pulumi.RegisterInputType(reflect.TypeOf((*UserPolicyAttachmentArrayInput)(nil)).Elem(), UserPolicyAttachmentArray{})
   286  	pulumi.RegisterInputType(reflect.TypeOf((*UserPolicyAttachmentMapInput)(nil)).Elem(), UserPolicyAttachmentMap{})
   287  	pulumi.RegisterOutputType(UserPolicyAttachmentOutput{})
   288  	pulumi.RegisterOutputType(UserPolicyAttachmentArrayOutput{})
   289  	pulumi.RegisterOutputType(UserPolicyAttachmentMapOutput{})
   290  }