1. Packages
  2. AWS Classic
  3. API Docs
  4. iam
  5. User

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.23.0 published on Thursday, Feb 22, 2024 by Pulumi

aws.iam.User

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.23.0 published on Thursday, Feb 22, 2024 by Pulumi

    Provides an IAM user.

    NOTE: If policies are attached to the user via the aws.iam.PolicyAttachment resource and you are modifying the user name or path, the force_destroy argument must be set to true and applied before attempting the operation otherwise you will encounter a DeleteConflict error. The aws.iam.UserPolicyAttachment resource (recommended) does not have this requirement.

    Example Usage

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var lbUser = new Aws.Iam.User("lbUser", new()
        {
            Path = "/system/",
            Tags = 
            {
                { "tag-key", "tag-value" },
            },
        });
    
        var lbAccessKey = new Aws.Iam.AccessKey("lbAccessKey", new()
        {
            User = lbUser.Name,
        });
    
        var lbRoPolicyDocument = Aws.Iam.GetPolicyDocument.Invoke(new()
        {
            Statements = new[]
            {
                new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
                {
                    Effect = "Allow",
                    Actions = new[]
                    {
                        "ec2:Describe*",
                    },
                    Resources = new[]
                    {
                        "*",
                    },
                },
            },
        });
    
        var lbRoUserPolicy = new Aws.Iam.UserPolicy("lbRoUserPolicy", new()
        {
            User = lbUser.Name,
            Policy = lbRoPolicyDocument.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		lbUser, err := iam.NewUser(ctx, "lbUser", &iam.UserArgs{
    			Path: pulumi.String("/system/"),
    			Tags: pulumi.StringMap{
    				"tag-key": pulumi.String("tag-value"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = iam.NewAccessKey(ctx, "lbAccessKey", &iam.AccessKeyArgs{
    			User: lbUser.Name,
    		})
    		if err != nil {
    			return err
    		}
    		lbRoPolicyDocument, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
    			Statements: []iam.GetPolicyDocumentStatement{
    				{
    					Effect: pulumi.StringRef("Allow"),
    					Actions: []string{
    						"ec2:Describe*",
    					},
    					Resources: []string{
    						"*",
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = iam.NewUserPolicy(ctx, "lbRoUserPolicy", &iam.UserPolicyArgs{
    			User:   lbUser.Name,
    			Policy: *pulumi.String(lbRoPolicyDocument.Json),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.iam.User;
    import com.pulumi.aws.iam.UserArgs;
    import com.pulumi.aws.iam.AccessKey;
    import com.pulumi.aws.iam.AccessKeyArgs;
    import com.pulumi.aws.iam.IamFunctions;
    import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
    import com.pulumi.aws.iam.UserPolicy;
    import com.pulumi.aws.iam.UserPolicyArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var lbUser = new User("lbUser", UserArgs.builder()        
                .path("/system/")
                .tags(Map.of("tag-key", "tag-value"))
                .build());
    
            var lbAccessKey = new AccessKey("lbAccessKey", AccessKeyArgs.builder()        
                .user(lbUser.name())
                .build());
    
            final var lbRoPolicyDocument = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                .statements(GetPolicyDocumentStatementArgs.builder()
                    .effect("Allow")
                    .actions("ec2:Describe*")
                    .resources("*")
                    .build())
                .build());
    
            var lbRoUserPolicy = new UserPolicy("lbRoUserPolicy", UserPolicyArgs.builder()        
                .user(lbUser.name())
                .policy(lbRoPolicyDocument.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json()))
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_aws as aws
    
    lb_user = aws.iam.User("lbUser",
        path="/system/",
        tags={
            "tag-key": "tag-value",
        })
    lb_access_key = aws.iam.AccessKey("lbAccessKey", user=lb_user.name)
    lb_ro_policy_document = aws.iam.get_policy_document(statements=[aws.iam.GetPolicyDocumentStatementArgs(
        effect="Allow",
        actions=["ec2:Describe*"],
        resources=["*"],
    )])
    lb_ro_user_policy = aws.iam.UserPolicy("lbRoUserPolicy",
        user=lb_user.name,
        policy=lb_ro_policy_document.json)
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const lbUser = new aws.iam.User("lbUser", {
        path: "/system/",
        tags: {
            "tag-key": "tag-value",
        },
    });
    const lbAccessKey = new aws.iam.AccessKey("lbAccessKey", {user: lbUser.name});
    const lbRoPolicyDocument = aws.iam.getPolicyDocument({
        statements: [{
            effect: "Allow",
            actions: ["ec2:Describe*"],
            resources: ["*"],
        }],
    });
    const lbRoUserPolicy = new aws.iam.UserPolicy("lbRoUserPolicy", {
        user: lbUser.name,
        policy: lbRoPolicyDocument.then(lbRoPolicyDocument => lbRoPolicyDocument.json),
    });
    
    resources:
      lbUser:
        type: aws:iam:User
        properties:
          path: /system/
          tags:
            tag-key: tag-value
      lbAccessKey:
        type: aws:iam:AccessKey
        properties:
          user: ${lbUser.name}
      lbRoUserPolicy:
        type: aws:iam:UserPolicy
        properties:
          user: ${lbUser.name}
          policy: ${lbRoPolicyDocument.json}
    variables:
      lbRoPolicyDocument:
        fn::invoke:
          Function: aws:iam:getPolicyDocument
          Arguments:
            statements:
              - effect: Allow
                actions:
                  - ec2:Describe*
                resources:
                  - '*'
    

    Create User Resource

    new User(name: string, args?: UserArgs, opts?: CustomResourceOptions);
    @overload
    def User(resource_name: str,
             opts: Optional[ResourceOptions] = None,
             force_destroy: Optional[bool] = None,
             name: Optional[str] = None,
             path: Optional[str] = None,
             permissions_boundary: Optional[str] = None,
             tags: Optional[Mapping[str, str]] = None)
    @overload
    def User(resource_name: str,
             args: Optional[UserArgs] = None,
             opts: Optional[ResourceOptions] = None)
    func NewUser(ctx *Context, name string, args *UserArgs, opts ...ResourceOption) (*User, error)
    public User(string name, UserArgs? args = null, CustomResourceOptions? opts = null)
    public User(String name, UserArgs args)
    public User(String name, UserArgs args, CustomResourceOptions options)
    
    type: aws:iam:User
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args UserArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args UserArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args UserArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args UserArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args UserArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    User Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The User resource accepts the following input properties:

    ForceDestroy bool
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    Name string
    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".
    Path string
    Path in which to create the user.
    PermissionsBoundary string
    The ARN of the policy that is used to set the permissions boundary for the user.
    Tags Dictionary<string, string>
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    ForceDestroy bool
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    Name string
    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".
    Path string
    Path in which to create the user.
    PermissionsBoundary string
    The ARN of the policy that is used to set the permissions boundary for the user.
    Tags map[string]string
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    forceDestroy Boolean
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    name String
    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".
    path String
    Path in which to create the user.
    permissionsBoundary String
    The ARN of the policy that is used to set the permissions boundary for the user.
    tags Map<String,String>
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    forceDestroy boolean
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    name string
    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".
    path string
    Path in which to create the user.
    permissionsBoundary string
    The ARN of the policy that is used to set the permissions boundary for the user.
    tags {[key: string]: string}
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    force_destroy bool
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    name str
    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".
    path str
    Path in which to create the user.
    permissions_boundary str
    The ARN of the policy that is used to set the permissions boundary for the user.
    tags Mapping[str, str]
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    forceDestroy Boolean
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    name String
    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".
    path String
    Path in which to create the user.
    permissionsBoundary String
    The ARN of the policy that is used to set the permissions boundary for the user.
    tags Map<String>
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the User resource produces the following output properties:

    Arn string
    The ARN assigned by AWS for this user.
    Id string
    The provider-assigned unique ID for this managed resource.
    TagsAll Dictionary<string, string>
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    UniqueId string
    The [unique ID][1] assigned by AWS.
    Arn string
    The ARN assigned by AWS for this user.
    Id string
    The provider-assigned unique ID for this managed resource.
    TagsAll map[string]string
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    UniqueId string
    The [unique ID][1] assigned by AWS.
    arn String
    The ARN assigned by AWS for this user.
    id String
    The provider-assigned unique ID for this managed resource.
    tagsAll Map<String,String>
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    uniqueId String
    The [unique ID][1] assigned by AWS.
    arn string
    The ARN assigned by AWS for this user.
    id string
    The provider-assigned unique ID for this managed resource.
    tagsAll {[key: string]: string}
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    uniqueId string
    The [unique ID][1] assigned by AWS.
    arn str
    The ARN assigned by AWS for this user.
    id str
    The provider-assigned unique ID for this managed resource.
    tags_all Mapping[str, str]
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    unique_id str
    The [unique ID][1] assigned by AWS.
    arn String
    The ARN assigned by AWS for this user.
    id String
    The provider-assigned unique ID for this managed resource.
    tagsAll Map<String>
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    uniqueId String
    The [unique ID][1] assigned by AWS.

    Look up Existing User Resource

    Get an existing User resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: UserState, opts?: CustomResourceOptions): User
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            arn: Optional[str] = None,
            force_destroy: Optional[bool] = None,
            name: Optional[str] = None,
            path: Optional[str] = None,
            permissions_boundary: Optional[str] = None,
            tags: Optional[Mapping[str, str]] = None,
            tags_all: Optional[Mapping[str, str]] = None,
            unique_id: Optional[str] = None) -> User
    func GetUser(ctx *Context, name string, id IDInput, state *UserState, opts ...ResourceOption) (*User, error)
    public static User Get(string name, Input<string> id, UserState? state, CustomResourceOptions? opts = null)
    public static User get(String name, Output<String> id, UserState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Arn string
    The ARN assigned by AWS for this user.
    ForceDestroy bool
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    Name string
    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".
    Path string
    Path in which to create the user.
    PermissionsBoundary string
    The ARN of the policy that is used to set the permissions boundary for the user.
    Tags Dictionary<string, string>
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    TagsAll Dictionary<string, string>
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    UniqueId string
    The [unique ID][1] assigned by AWS.
    Arn string
    The ARN assigned by AWS for this user.
    ForceDestroy bool
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    Name string
    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".
    Path string
    Path in which to create the user.
    PermissionsBoundary string
    The ARN of the policy that is used to set the permissions boundary for the user.
    Tags map[string]string
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    TagsAll map[string]string
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    UniqueId string
    The [unique ID][1] assigned by AWS.
    arn String
    The ARN assigned by AWS for this user.
    forceDestroy Boolean
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    name String
    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".
    path String
    Path in which to create the user.
    permissionsBoundary String
    The ARN of the policy that is used to set the permissions boundary for the user.
    tags Map<String,String>
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    tagsAll Map<String,String>
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    uniqueId String
    The [unique ID][1] assigned by AWS.
    arn string
    The ARN assigned by AWS for this user.
    forceDestroy boolean
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    name string
    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".
    path string
    Path in which to create the user.
    permissionsBoundary string
    The ARN of the policy that is used to set the permissions boundary for the user.
    tags {[key: string]: string}
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    tagsAll {[key: string]: string}
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    uniqueId string
    The [unique ID][1] assigned by AWS.
    arn str
    The ARN assigned by AWS for this user.
    force_destroy bool
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    name str
    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".
    path str
    Path in which to create the user.
    permissions_boundary str
    The ARN of the policy that is used to set the permissions boundary for the user.
    tags Mapping[str, str]
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    tags_all Mapping[str, str]
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    unique_id str
    The [unique ID][1] assigned by AWS.
    arn String
    The ARN assigned by AWS for this user.
    forceDestroy Boolean
    When destroying this user, destroy even if it has non-provider-managed IAM access keys, login profile or MFA devices. Without force_destroy a user with non-provider-managed access keys and login profile will fail to be destroyed.
    name String
    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".
    path String
    Path in which to create the user.
    permissionsBoundary String
    The ARN of the policy that is used to set the permissions boundary for the user.
    tags Map<String>
    Key-value mapping of tags for the IAM user. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    tagsAll Map<String>
    A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

    Deprecated:Please use tags instead.

    uniqueId String
    The [unique ID][1] assigned by AWS.

    Import

    Using pulumi import, import IAM Users using the name. For example:

     $ pulumi import aws:iam/user:User lb loadbalancer
    

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.23.0 published on Thursday, Feb 22, 2024 by Pulumi