github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iam/user.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  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    11  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    12  )
    13  
    14  // Provides an IAM user.
    15  //
    16  // > *NOTE:* If policies are attached to the user via the `iam.PolicyAttachment` resource and you are modifying the user `name` or `path`, the `forceDestroy` argument must be set to `true` and applied before attempting the operation otherwise you will encounter a `DeleteConflict` error. The `iam.UserPolicyAttachment` resource (recommended) does not have this requirement.
    17  //
    18  // ## Example Usage
    19  //
    20  // <!--Start PulumiCodeChooser -->
    21  // ```go
    22  // package main
    23  //
    24  // import (
    25  //
    26  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    27  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    28  //
    29  // )
    30  //
    31  //	func main() {
    32  //		pulumi.Run(func(ctx *pulumi.Context) error {
    33  //			lb, err := iam.NewUser(ctx, "lb", &iam.UserArgs{
    34  //				Name: pulumi.String("loadbalancer"),
    35  //				Path: pulumi.String("/system/"),
    36  //				Tags: pulumi.StringMap{
    37  //					"tag-key": pulumi.String("tag-value"),
    38  //				},
    39  //			})
    40  //			if err != nil {
    41  //				return err
    42  //			}
    43  //			_, err = iam.NewAccessKey(ctx, "lb", &iam.AccessKeyArgs{
    44  //				User: lb.Name,
    45  //			})
    46  //			if err != nil {
    47  //				return err
    48  //			}
    49  //			lbRo, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
    50  //				Statements: []iam.GetPolicyDocumentStatement{
    51  //					{
    52  //						Effect: pulumi.StringRef("Allow"),
    53  //						Actions: []string{
    54  //							"ec2:Describe*",
    55  //						},
    56  //						Resources: []string{
    57  //							"*",
    58  //						},
    59  //					},
    60  //				},
    61  //			}, nil)
    62  //			if err != nil {
    63  //				return err
    64  //			}
    65  //			_, err = iam.NewUserPolicy(ctx, "lb_ro", &iam.UserPolicyArgs{
    66  //				Name:   pulumi.String("test"),
    67  //				User:   lb.Name,
    68  //				Policy: pulumi.String(lbRo.Json),
    69  //			})
    70  //			if err != nil {
    71  //				return err
    72  //			}
    73  //			return nil
    74  //		})
    75  //	}
    76  //
    77  // ```
    78  // <!--End PulumiCodeChooser -->
    79  //
    80  // ## Import
    81  //
    82  // Using `pulumi import`, import IAM Users using the `name`. For example:
    83  //
    84  // ```sh
    85  // $ pulumi import aws:iam/user:User lb loadbalancer
    86  // ```
    87  type User struct {
    88  	pulumi.CustomResourceState
    89  
    90  	// The ARN assigned by AWS for this user.
    91  	Arn pulumi.StringOutput `pulumi:"arn"`
    92  	// When destroying this user, destroy even if it
    93  	// has non-provider-managed IAM access keys, login profile or MFA devices. Without `forceDestroy`
    94  	// a user with non-provider-managed access keys and login profile will fail to be destroyed.
    95  	ForceDestroy pulumi.BoolPtrOutput `pulumi:"forceDestroy"`
    96  	// The user's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-_.`. User names are not distinguished by case. For example, you cannot create users named both "TESTUSER" and "testuser".
    97  	Name pulumi.StringOutput `pulumi:"name"`
    98  	// Path in which to create the user.
    99  	Path pulumi.StringPtrOutput `pulumi:"path"`
   100  	// The ARN of the policy that is used to set the permissions boundary for the user.
   101  	PermissionsBoundary pulumi.StringPtrOutput `pulumi:"permissionsBoundary"`
   102  	// Key-value mapping of tags for the IAM user. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   103  	Tags pulumi.StringMapOutput `pulumi:"tags"`
   104  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   105  	//
   106  	// Deprecated: Please use `tags` instead.
   107  	TagsAll pulumi.StringMapOutput `pulumi:"tagsAll"`
   108  	// The [unique ID][1] assigned by AWS.
   109  	UniqueId pulumi.StringOutput `pulumi:"uniqueId"`
   110  }
   111  
   112  // NewUser registers a new resource with the given unique name, arguments, and options.
   113  func NewUser(ctx *pulumi.Context,
   114  	name string, args *UserArgs, opts ...pulumi.ResourceOption) (*User, error) {
   115  	if args == nil {
   116  		args = &UserArgs{}
   117  	}
   118  
   119  	opts = internal.PkgResourceDefaultOpts(opts)
   120  	var resource User
   121  	err := ctx.RegisterResource("aws:iam/user:User", name, args, &resource, opts...)
   122  	if err != nil {
   123  		return nil, err
   124  	}
   125  	return &resource, nil
   126  }
   127  
   128  // GetUser gets an existing User resource's state with the given name, ID, and optional
   129  // state properties that are used to uniquely qualify the lookup (nil if not required).
   130  func GetUser(ctx *pulumi.Context,
   131  	name string, id pulumi.IDInput, state *UserState, opts ...pulumi.ResourceOption) (*User, error) {
   132  	var resource User
   133  	err := ctx.ReadResource("aws:iam/user:User", name, id, state, &resource, opts...)
   134  	if err != nil {
   135  		return nil, err
   136  	}
   137  	return &resource, nil
   138  }
   139  
   140  // Input properties used for looking up and filtering User resources.
   141  type userState struct {
   142  	// The ARN assigned by AWS for this user.
   143  	Arn *string `pulumi:"arn"`
   144  	// When destroying this user, destroy even if it
   145  	// has non-provider-managed IAM access keys, login profile or MFA devices. Without `forceDestroy`
   146  	// a user with non-provider-managed access keys and login profile will fail to be destroyed.
   147  	ForceDestroy *bool `pulumi:"forceDestroy"`
   148  	// The user's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-_.`. User names are not distinguished by case. For example, you cannot create users named both "TESTUSER" and "testuser".
   149  	Name *string `pulumi:"name"`
   150  	// Path in which to create the user.
   151  	Path *string `pulumi:"path"`
   152  	// The ARN of the policy that is used to set the permissions boundary for the user.
   153  	PermissionsBoundary *string `pulumi:"permissionsBoundary"`
   154  	// Key-value mapping of tags for the IAM user. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   155  	Tags map[string]string `pulumi:"tags"`
   156  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   157  	//
   158  	// Deprecated: Please use `tags` instead.
   159  	TagsAll map[string]string `pulumi:"tagsAll"`
   160  	// The [unique ID][1] assigned by AWS.
   161  	UniqueId *string `pulumi:"uniqueId"`
   162  }
   163  
   164  type UserState struct {
   165  	// The ARN assigned by AWS for this user.
   166  	Arn pulumi.StringPtrInput
   167  	// When destroying this user, destroy even if it
   168  	// has non-provider-managed IAM access keys, login profile or MFA devices. Without `forceDestroy`
   169  	// a user with non-provider-managed access keys and login profile will fail to be destroyed.
   170  	ForceDestroy pulumi.BoolPtrInput
   171  	// The user's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-_.`. User names are not distinguished by case. For example, you cannot create users named both "TESTUSER" and "testuser".
   172  	Name pulumi.StringPtrInput
   173  	// Path in which to create the user.
   174  	Path pulumi.StringPtrInput
   175  	// The ARN of the policy that is used to set the permissions boundary for the user.
   176  	PermissionsBoundary pulumi.StringPtrInput
   177  	// Key-value mapping of tags for the IAM user. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   178  	Tags pulumi.StringMapInput
   179  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   180  	//
   181  	// Deprecated: Please use `tags` instead.
   182  	TagsAll pulumi.StringMapInput
   183  	// The [unique ID][1] assigned by AWS.
   184  	UniqueId pulumi.StringPtrInput
   185  }
   186  
   187  func (UserState) ElementType() reflect.Type {
   188  	return reflect.TypeOf((*userState)(nil)).Elem()
   189  }
   190  
   191  type userArgs struct {
   192  	// When destroying this user, destroy even if it
   193  	// has non-provider-managed IAM access keys, login profile or MFA devices. Without `forceDestroy`
   194  	// a user with non-provider-managed access keys and login profile will fail to be destroyed.
   195  	ForceDestroy *bool `pulumi:"forceDestroy"`
   196  	// The user's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-_.`. User names are not distinguished by case. For example, you cannot create users named both "TESTUSER" and "testuser".
   197  	Name *string `pulumi:"name"`
   198  	// Path in which to create the user.
   199  	Path *string `pulumi:"path"`
   200  	// The ARN of the policy that is used to set the permissions boundary for the user.
   201  	PermissionsBoundary *string `pulumi:"permissionsBoundary"`
   202  	// Key-value mapping of tags for the IAM user. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   203  	Tags map[string]string `pulumi:"tags"`
   204  }
   205  
   206  // The set of arguments for constructing a User resource.
   207  type UserArgs struct {
   208  	// When destroying this user, destroy even if it
   209  	// has non-provider-managed IAM access keys, login profile or MFA devices. Without `forceDestroy`
   210  	// a user with non-provider-managed access keys and login profile will fail to be destroyed.
   211  	ForceDestroy pulumi.BoolPtrInput
   212  	// The user's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-_.`. User names are not distinguished by case. For example, you cannot create users named both "TESTUSER" and "testuser".
   213  	Name pulumi.StringPtrInput
   214  	// Path in which to create the user.
   215  	Path pulumi.StringPtrInput
   216  	// The ARN of the policy that is used to set the permissions boundary for the user.
   217  	PermissionsBoundary pulumi.StringPtrInput
   218  	// Key-value mapping of tags for the IAM user. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   219  	Tags pulumi.StringMapInput
   220  }
   221  
   222  func (UserArgs) ElementType() reflect.Type {
   223  	return reflect.TypeOf((*userArgs)(nil)).Elem()
   224  }
   225  
   226  type UserInput interface {
   227  	pulumi.Input
   228  
   229  	ToUserOutput() UserOutput
   230  	ToUserOutputWithContext(ctx context.Context) UserOutput
   231  }
   232  
   233  func (*User) ElementType() reflect.Type {
   234  	return reflect.TypeOf((**User)(nil)).Elem()
   235  }
   236  
   237  func (i *User) ToUserOutput() UserOutput {
   238  	return i.ToUserOutputWithContext(context.Background())
   239  }
   240  
   241  func (i *User) ToUserOutputWithContext(ctx context.Context) UserOutput {
   242  	return pulumi.ToOutputWithContext(ctx, i).(UserOutput)
   243  }
   244  
   245  // UserArrayInput is an input type that accepts UserArray and UserArrayOutput values.
   246  // You can construct a concrete instance of `UserArrayInput` via:
   247  //
   248  //	UserArray{ UserArgs{...} }
   249  type UserArrayInput interface {
   250  	pulumi.Input
   251  
   252  	ToUserArrayOutput() UserArrayOutput
   253  	ToUserArrayOutputWithContext(context.Context) UserArrayOutput
   254  }
   255  
   256  type UserArray []UserInput
   257  
   258  func (UserArray) ElementType() reflect.Type {
   259  	return reflect.TypeOf((*[]*User)(nil)).Elem()
   260  }
   261  
   262  func (i UserArray) ToUserArrayOutput() UserArrayOutput {
   263  	return i.ToUserArrayOutputWithContext(context.Background())
   264  }
   265  
   266  func (i UserArray) ToUserArrayOutputWithContext(ctx context.Context) UserArrayOutput {
   267  	return pulumi.ToOutputWithContext(ctx, i).(UserArrayOutput)
   268  }
   269  
   270  // UserMapInput is an input type that accepts UserMap and UserMapOutput values.
   271  // You can construct a concrete instance of `UserMapInput` via:
   272  //
   273  //	UserMap{ "key": UserArgs{...} }
   274  type UserMapInput interface {
   275  	pulumi.Input
   276  
   277  	ToUserMapOutput() UserMapOutput
   278  	ToUserMapOutputWithContext(context.Context) UserMapOutput
   279  }
   280  
   281  type UserMap map[string]UserInput
   282  
   283  func (UserMap) ElementType() reflect.Type {
   284  	return reflect.TypeOf((*map[string]*User)(nil)).Elem()
   285  }
   286  
   287  func (i UserMap) ToUserMapOutput() UserMapOutput {
   288  	return i.ToUserMapOutputWithContext(context.Background())
   289  }
   290  
   291  func (i UserMap) ToUserMapOutputWithContext(ctx context.Context) UserMapOutput {
   292  	return pulumi.ToOutputWithContext(ctx, i).(UserMapOutput)
   293  }
   294  
   295  type UserOutput struct{ *pulumi.OutputState }
   296  
   297  func (UserOutput) ElementType() reflect.Type {
   298  	return reflect.TypeOf((**User)(nil)).Elem()
   299  }
   300  
   301  func (o UserOutput) ToUserOutput() UserOutput {
   302  	return o
   303  }
   304  
   305  func (o UserOutput) ToUserOutputWithContext(ctx context.Context) UserOutput {
   306  	return o
   307  }
   308  
   309  // The ARN assigned by AWS for this user.
   310  func (o UserOutput) Arn() pulumi.StringOutput {
   311  	return o.ApplyT(func(v *User) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput)
   312  }
   313  
   314  // When destroying this user, destroy even if it
   315  // has non-provider-managed IAM access keys, login profile or MFA devices. Without `forceDestroy`
   316  // a user with non-provider-managed access keys and login profile will fail to be destroyed.
   317  func (o UserOutput) ForceDestroy() pulumi.BoolPtrOutput {
   318  	return o.ApplyT(func(v *User) pulumi.BoolPtrOutput { return v.ForceDestroy }).(pulumi.BoolPtrOutput)
   319  }
   320  
   321  // The user's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-_.`. User names are not distinguished by case. For example, you cannot create users named both "TESTUSER" and "testuser".
   322  func (o UserOutput) Name() pulumi.StringOutput {
   323  	return o.ApplyT(func(v *User) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
   324  }
   325  
   326  // Path in which to create the user.
   327  func (o UserOutput) Path() pulumi.StringPtrOutput {
   328  	return o.ApplyT(func(v *User) pulumi.StringPtrOutput { return v.Path }).(pulumi.StringPtrOutput)
   329  }
   330  
   331  // The ARN of the policy that is used to set the permissions boundary for the user.
   332  func (o UserOutput) PermissionsBoundary() pulumi.StringPtrOutput {
   333  	return o.ApplyT(func(v *User) pulumi.StringPtrOutput { return v.PermissionsBoundary }).(pulumi.StringPtrOutput)
   334  }
   335  
   336  // Key-value mapping of tags for the IAM user. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   337  func (o UserOutput) Tags() pulumi.StringMapOutput {
   338  	return o.ApplyT(func(v *User) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput)
   339  }
   340  
   341  // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   342  //
   343  // Deprecated: Please use `tags` instead.
   344  func (o UserOutput) TagsAll() pulumi.StringMapOutput {
   345  	return o.ApplyT(func(v *User) pulumi.StringMapOutput { return v.TagsAll }).(pulumi.StringMapOutput)
   346  }
   347  
   348  // The [unique ID][1] assigned by AWS.
   349  func (o UserOutput) UniqueId() pulumi.StringOutput {
   350  	return o.ApplyT(func(v *User) pulumi.StringOutput { return v.UniqueId }).(pulumi.StringOutput)
   351  }
   352  
   353  type UserArrayOutput struct{ *pulumi.OutputState }
   354  
   355  func (UserArrayOutput) ElementType() reflect.Type {
   356  	return reflect.TypeOf((*[]*User)(nil)).Elem()
   357  }
   358  
   359  func (o UserArrayOutput) ToUserArrayOutput() UserArrayOutput {
   360  	return o
   361  }
   362  
   363  func (o UserArrayOutput) ToUserArrayOutputWithContext(ctx context.Context) UserArrayOutput {
   364  	return o
   365  }
   366  
   367  func (o UserArrayOutput) Index(i pulumi.IntInput) UserOutput {
   368  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *User {
   369  		return vs[0].([]*User)[vs[1].(int)]
   370  	}).(UserOutput)
   371  }
   372  
   373  type UserMapOutput struct{ *pulumi.OutputState }
   374  
   375  func (UserMapOutput) ElementType() reflect.Type {
   376  	return reflect.TypeOf((*map[string]*User)(nil)).Elem()
   377  }
   378  
   379  func (o UserMapOutput) ToUserMapOutput() UserMapOutput {
   380  	return o
   381  }
   382  
   383  func (o UserMapOutput) ToUserMapOutputWithContext(ctx context.Context) UserMapOutput {
   384  	return o
   385  }
   386  
   387  func (o UserMapOutput) MapIndex(k pulumi.StringInput) UserOutput {
   388  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *User {
   389  		return vs[0].(map[string]*User)[vs[1].(string)]
   390  	}).(UserOutput)
   391  }
   392  
   393  func init() {
   394  	pulumi.RegisterInputType(reflect.TypeOf((*UserInput)(nil)).Elem(), &User{})
   395  	pulumi.RegisterInputType(reflect.TypeOf((*UserArrayInput)(nil)).Elem(), UserArray{})
   396  	pulumi.RegisterInputType(reflect.TypeOf((*UserMapInput)(nil)).Elem(), UserMap{})
   397  	pulumi.RegisterOutputType(UserOutput{})
   398  	pulumi.RegisterOutputType(UserArrayOutput{})
   399  	pulumi.RegisterOutputType(UserMapOutput{})
   400  }