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

aws.iam.UserGroupMembership

Explore with Pulumi AI

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

    Provides a resource for adding an IAM User to IAM Groups. This resource can be used multiple times with the same user for non-overlapping groups.

    To exclusively manage the users in a group, see the aws.iam.GroupMembership resource.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const user1 = new aws.iam.User("user1", {name: "user1"});
    const group1 = new aws.iam.Group("group1", {name: "group1"});
    const group2 = new aws.iam.Group("group2", {name: "group2"});
    const example1 = new aws.iam.UserGroupMembership("example1", {
        user: user1.name,
        groups: [
            group1.name,
            group2.name,
        ],
    });
    const group3 = new aws.iam.Group("group3", {name: "group3"});
    const example2 = new aws.iam.UserGroupMembership("example2", {
        user: user1.name,
        groups: [group3.name],
    });
    
    import pulumi
    import pulumi_aws as aws
    
    user1 = aws.iam.User("user1", name="user1")
    group1 = aws.iam.Group("group1", name="group1")
    group2 = aws.iam.Group("group2", name="group2")
    example1 = aws.iam.UserGroupMembership("example1",
        user=user1.name,
        groups=[
            group1.name,
            group2.name,
        ])
    group3 = aws.iam.Group("group3", name="group3")
    example2 = aws.iam.UserGroupMembership("example2",
        user=user1.name,
        groups=[group3.name])
    
    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 {
    		user1, err := iam.NewUser(ctx, "user1", &iam.UserArgs{
    			Name: pulumi.String("user1"),
    		})
    		if err != nil {
    			return err
    		}
    		group1, err := iam.NewGroup(ctx, "group1", &iam.GroupArgs{
    			Name: pulumi.String("group1"),
    		})
    		if err != nil {
    			return err
    		}
    		group2, err := iam.NewGroup(ctx, "group2", &iam.GroupArgs{
    			Name: pulumi.String("group2"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = iam.NewUserGroupMembership(ctx, "example1", &iam.UserGroupMembershipArgs{
    			User: user1.Name,
    			Groups: pulumi.StringArray{
    				group1.Name,
    				group2.Name,
    			},
    		})
    		if err != nil {
    			return err
    		}
    		group3, err := iam.NewGroup(ctx, "group3", &iam.GroupArgs{
    			Name: pulumi.String("group3"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = iam.NewUserGroupMembership(ctx, "example2", &iam.UserGroupMembershipArgs{
    			User: user1.Name,
    			Groups: pulumi.StringArray{
    				group3.Name,
    			},
    		})
    		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 user1 = new Aws.Iam.User("user1", new()
        {
            Name = "user1",
        });
    
        var group1 = new Aws.Iam.Group("group1", new()
        {
            Name = "group1",
        });
    
        var group2 = new Aws.Iam.Group("group2", new()
        {
            Name = "group2",
        });
    
        var example1 = new Aws.Iam.UserGroupMembership("example1", new()
        {
            User = user1.Name,
            Groups = new[]
            {
                group1.Name,
                group2.Name,
            },
        });
    
        var group3 = new Aws.Iam.Group("group3", new()
        {
            Name = "group3",
        });
    
        var example2 = new Aws.Iam.UserGroupMembership("example2", new()
        {
            User = user1.Name,
            Groups = new[]
            {
                group3.Name,
            },
        });
    
    });
    
    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.Group;
    import com.pulumi.aws.iam.GroupArgs;
    import com.pulumi.aws.iam.UserGroupMembership;
    import com.pulumi.aws.iam.UserGroupMembershipArgs;
    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 user1 = new User("user1", UserArgs.builder()
                .name("user1")
                .build());
    
            var group1 = new Group("group1", GroupArgs.builder()
                .name("group1")
                .build());
    
            var group2 = new Group("group2", GroupArgs.builder()
                .name("group2")
                .build());
    
            var example1 = new UserGroupMembership("example1", UserGroupMembershipArgs.builder()
                .user(user1.name())
                .groups(            
                    group1.name(),
                    group2.name())
                .build());
    
            var group3 = new Group("group3", GroupArgs.builder()
                .name("group3")
                .build());
    
            var example2 = new UserGroupMembership("example2", UserGroupMembershipArgs.builder()
                .user(user1.name())
                .groups(group3.name())
                .build());
    
        }
    }
    
    resources:
      example1:
        type: aws:iam:UserGroupMembership
        properties:
          user: ${user1.name}
          groups:
            - ${group1.name}
            - ${group2.name}
      example2:
        type: aws:iam:UserGroupMembership
        properties:
          user: ${user1.name}
          groups:
            - ${group3.name}
      user1:
        type: aws:iam:User
        properties:
          name: user1
      group1:
        type: aws:iam:Group
        properties:
          name: group1
      group2:
        type: aws:iam:Group
        properties:
          name: group2
      group3:
        type: aws:iam:Group
        properties:
          name: group3
    

    Create UserGroupMembership Resource

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

    Constructor syntax

    new UserGroupMembership(name: string, args: UserGroupMembershipArgs, opts?: CustomResourceOptions);
    @overload
    def UserGroupMembership(resource_name: str,
                            args: UserGroupMembershipArgs,
                            opts: Optional[ResourceOptions] = None)
    
    @overload
    def UserGroupMembership(resource_name: str,
                            opts: Optional[ResourceOptions] = None,
                            groups: Optional[Sequence[str]] = None,
                            user: Optional[str] = None)
    func NewUserGroupMembership(ctx *Context, name string, args UserGroupMembershipArgs, opts ...ResourceOption) (*UserGroupMembership, error)
    public UserGroupMembership(string name, UserGroupMembershipArgs args, CustomResourceOptions? opts = null)
    public UserGroupMembership(String name, UserGroupMembershipArgs args)
    public UserGroupMembership(String name, UserGroupMembershipArgs args, CustomResourceOptions options)
    
    type: aws:iam:UserGroupMembership
    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 UserGroupMembershipArgs
    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 UserGroupMembershipArgs
    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 UserGroupMembershipArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args UserGroupMembershipArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args UserGroupMembershipArgs
    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 userGroupMembershipResource = new Aws.Iam.UserGroupMembership("userGroupMembershipResource", new()
    {
        Groups = new[]
        {
            "string",
        },
        User = "string",
    });
    
    example, err := iam.NewUserGroupMembership(ctx, "userGroupMembershipResource", &iam.UserGroupMembershipArgs{
    	Groups: pulumi.StringArray{
    		pulumi.String("string"),
    	},
    	User: pulumi.String("string"),
    })
    
    var userGroupMembershipResource = new UserGroupMembership("userGroupMembershipResource", UserGroupMembershipArgs.builder()
        .groups("string")
        .user("string")
        .build());
    
    user_group_membership_resource = aws.iam.UserGroupMembership("userGroupMembershipResource",
        groups=["string"],
        user="string")
    
    const userGroupMembershipResource = new aws.iam.UserGroupMembership("userGroupMembershipResource", {
        groups: ["string"],
        user: "string",
    });
    
    type: aws:iam:UserGroupMembership
    properties:
        groups:
            - string
        user: string
    

    UserGroupMembership 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 UserGroupMembership resource accepts the following input properties:

    Groups List<string>
    A list of IAM Groups to add the user to
    User string
    The name of the IAM User to add to groups
    Groups []string
    A list of IAM Groups to add the user to
    User string
    The name of the IAM User to add to groups
    groups List<String>
    A list of IAM Groups to add the user to
    user String
    The name of the IAM User to add to groups
    groups string[]
    A list of IAM Groups to add the user to
    user string
    The name of the IAM User to add to groups
    groups Sequence[str]
    A list of IAM Groups to add the user to
    user str
    The name of the IAM User to add to groups
    groups List<String>
    A list of IAM Groups to add the user to
    user String
    The name of the IAM User to add to groups

    Outputs

    All input properties are implicitly available as output properties. Additionally, the UserGroupMembership 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 UserGroupMembership Resource

    Get an existing UserGroupMembership 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?: UserGroupMembershipState, opts?: CustomResourceOptions): UserGroupMembership
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            groups: Optional[Sequence[str]] = None,
            user: Optional[str] = None) -> UserGroupMembership
    func GetUserGroupMembership(ctx *Context, name string, id IDInput, state *UserGroupMembershipState, opts ...ResourceOption) (*UserGroupMembership, error)
    public static UserGroupMembership Get(string name, Input<string> id, UserGroupMembershipState? state, CustomResourceOptions? opts = null)
    public static UserGroupMembership get(String name, Output<String> id, UserGroupMembershipState 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:
    Groups List<string>
    A list of IAM Groups to add the user to
    User string
    The name of the IAM User to add to groups
    Groups []string
    A list of IAM Groups to add the user to
    User string
    The name of the IAM User to add to groups
    groups List<String>
    A list of IAM Groups to add the user to
    user String
    The name of the IAM User to add to groups
    groups string[]
    A list of IAM Groups to add the user to
    user string
    The name of the IAM User to add to groups
    groups Sequence[str]
    A list of IAM Groups to add the user to
    user str
    The name of the IAM User to add to groups
    groups List<String>
    A list of IAM Groups to add the user to
    user String
    The name of the IAM User to add to groups

    Import

    Using pulumi import, import IAM user group membership using the user name and group names separated by /. For example:

    $ pulumi import aws:iam/userGroupMembership:UserGroupMembership example1 user1/group1/group2
    

    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