1. Packages
  2. AWS
  3. API Docs
  4. iam
  5. UserPolicyAttachment
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

aws.iam.UserPolicyAttachment

Explore with Pulumi AI

aws logo
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

    Attaches a Managed IAM Policy to an IAM user

    NOTE: The usage of this resource conflicts with the aws.iam.PolicyAttachment resource and will permanently show a difference if both are defined.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const user = new aws.iam.User("user", {name: "test-user"});
    const policy = new aws.iam.Policy("policy", {
        name: "test-policy",
        description: "A test policy",
        policy: "{ ... policy JSON ... }",
    });
    const test_attach = new aws.iam.UserPolicyAttachment("test-attach", {
        user: user.name,
        policyArn: policy.arn,
    });
    
    import pulumi
    import pulumi_aws as aws
    
    user = aws.iam.User("user", name="test-user")
    policy = aws.iam.Policy("policy",
        name="test-policy",
        description="A test policy",
        policy="{ ... policy JSON ... }")
    test_attach = aws.iam.UserPolicyAttachment("test-attach",
        user=user.name,
        policy_arn=policy.arn)
    
    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 {
    		user, err := iam.NewUser(ctx, "user", &iam.UserArgs{
    			Name: pulumi.String("test-user"),
    		})
    		if err != nil {
    			return err
    		}
    		policy, err := iam.NewPolicy(ctx, "policy", &iam.PolicyArgs{
    			Name:        pulumi.String("test-policy"),
    			Description: pulumi.String("A test policy"),
    			Policy:      pulumi.Any("{ ... policy JSON ... }"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = iam.NewUserPolicyAttachment(ctx, "test-attach", &iam.UserPolicyAttachmentArgs{
    			User:      user.Name,
    			PolicyArn: policy.Arn,
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var user = new Aws.Iam.User("user", new()
        {
            Name = "test-user",
        });
    
        var policy = new Aws.Iam.Policy("policy", new()
        {
            Name = "test-policy",
            Description = "A test policy",
            PolicyDocument = "{ ... policy JSON ... }",
        });
    
        var test_attach = new Aws.Iam.UserPolicyAttachment("test-attach", new()
        {
            User = user.Name,
            PolicyArn = policy.Arn,
        });
    
    });
    
    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.Policy;
    import com.pulumi.aws.iam.PolicyArgs;
    import com.pulumi.aws.iam.UserPolicyAttachment;
    import com.pulumi.aws.iam.UserPolicyAttachmentArgs;
    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 user = new User("user", UserArgs.builder()
                .name("test-user")
                .build());
    
            var policy = new Policy("policy", PolicyArgs.builder()
                .name("test-policy")
                .description("A test policy")
                .policy("{ ... policy JSON ... }")
                .build());
    
            var test_attach = new UserPolicyAttachment("test-attach", UserPolicyAttachmentArgs.builder()
                .user(user.name())
                .policyArn(policy.arn())
                .build());
    
        }
    }
    
    resources:
      user:
        type: aws:iam:User
        properties:
          name: test-user
      policy:
        type: aws:iam:Policy
        properties:
          name: test-policy
          description: A test policy
          policy: '{ ... policy JSON ... }'
      test-attach:
        type: aws:iam:UserPolicyAttachment
        properties:
          user: ${user.name}
          policyArn: ${policy.arn}
    

    Create UserPolicyAttachment Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new UserPolicyAttachment(name: string, args: UserPolicyAttachmentArgs, opts?: CustomResourceOptions);
    @overload
    def UserPolicyAttachment(resource_name: str,
                             args: UserPolicyAttachmentArgs,
                             opts: Optional[ResourceOptions] = None)
    
    @overload
    def UserPolicyAttachment(resource_name: str,
                             opts: Optional[ResourceOptions] = None,
                             policy_arn: Optional[str] = None,
                             user: Optional[str] = None)
    func NewUserPolicyAttachment(ctx *Context, name string, args UserPolicyAttachmentArgs, opts ...ResourceOption) (*UserPolicyAttachment, error)
    public UserPolicyAttachment(string name, UserPolicyAttachmentArgs args, CustomResourceOptions? opts = null)
    public UserPolicyAttachment(String name, UserPolicyAttachmentArgs args)
    public UserPolicyAttachment(String name, UserPolicyAttachmentArgs args, CustomResourceOptions options)
    
    type: aws:iam:UserPolicyAttachment
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args UserPolicyAttachmentArgs
    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 UserPolicyAttachmentArgs
    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 UserPolicyAttachmentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args UserPolicyAttachmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args UserPolicyAttachmentArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var userPolicyAttachmentResource = new Aws.Iam.UserPolicyAttachment("userPolicyAttachmentResource", new()
    {
        PolicyArn = "string",
        User = "string",
    });
    
    example, err := iam.NewUserPolicyAttachment(ctx, "userPolicyAttachmentResource", &iam.UserPolicyAttachmentArgs{
    	PolicyArn: pulumi.String("string"),
    	User:      pulumi.Any("string"),
    })
    
    var userPolicyAttachmentResource = new UserPolicyAttachment("userPolicyAttachmentResource", UserPolicyAttachmentArgs.builder()
        .policyArn("string")
        .user("string")
        .build());
    
    user_policy_attachment_resource = aws.iam.UserPolicyAttachment("userPolicyAttachmentResource",
        policy_arn="string",
        user="string")
    
    const userPolicyAttachmentResource = new aws.iam.UserPolicyAttachment("userPolicyAttachmentResource", {
        policyArn: "string",
        user: "string",
    });
    
    type: aws:iam:UserPolicyAttachment
    properties:
        policyArn: string
        user: string
    

    UserPolicyAttachment Resource Properties

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

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The UserPolicyAttachment resource accepts the following input properties:

    PolicyArn string
    The ARN of the policy you want to apply
    User string | string
    The user the policy should be applied to
    PolicyArn string
    The ARN of the policy you want to apply
    User string | string
    The user the policy should be applied to
    policyArn String
    The ARN of the policy you want to apply
    user String | String
    The user the policy should be applied to
    policyArn ARN
    The ARN of the policy you want to apply
    user string | User
    The user the policy should be applied to
    policy_arn str
    The ARN of the policy you want to apply
    user str | str
    The user the policy should be applied to
    policyArn
    The ARN of the policy you want to apply
    user String |
    The user the policy should be applied to

    Outputs

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

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing UserPolicyAttachment Resource

    Get an existing UserPolicyAttachment 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?: UserPolicyAttachmentState, opts?: CustomResourceOptions): UserPolicyAttachment
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            policy_arn: Optional[str] = None,
            user: Optional[str] = None) -> UserPolicyAttachment
    func GetUserPolicyAttachment(ctx *Context, name string, id IDInput, state *UserPolicyAttachmentState, opts ...ResourceOption) (*UserPolicyAttachment, error)
    public static UserPolicyAttachment Get(string name, Input<string> id, UserPolicyAttachmentState? state, CustomResourceOptions? opts = null)
    public static UserPolicyAttachment get(String name, Output<String> id, UserPolicyAttachmentState 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:
    PolicyArn string
    The ARN of the policy you want to apply
    User string | string
    The user the policy should be applied to
    PolicyArn string
    The ARN of the policy you want to apply
    User string | string
    The user the policy should be applied to
    policyArn String
    The ARN of the policy you want to apply
    user String | String
    The user the policy should be applied to
    policyArn ARN
    The ARN of the policy you want to apply
    user string | User
    The user the policy should be applied to
    policy_arn str
    The ARN of the policy you want to apply
    user str | str
    The user the policy should be applied to
    policyArn
    The ARN of the policy you want to apply
    user String |
    The user the policy should be applied to

    Import

    Using pulumi import, import IAM user policy attachments using the user name and policy arn separated by /. For example:

    $ pulumi import aws:iam/userPolicyAttachment:UserPolicyAttachment test-attach test-user/arn:aws:iam::xxxxxxxxxxxx:policy/test-policy
    

    To learn more about importing existing cloud resources, see Importing resources.

    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
    AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi