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

aws.cognito.UserGroup

Explore with Pulumi AI

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

    Provides a Cognito User Group resource.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const main = new aws.cognito.UserPool("main", {name: "identity pool"});
    const groupRole = aws.iam.getPolicyDocument({
        statements: [{
            effect: "Allow",
            principals: [{
                type: "Federated",
                identifiers: ["cognito-identity.amazonaws.com"],
            }],
            actions: ["sts:AssumeRoleWithWebIdentity"],
            conditions: [
                {
                    test: "StringEquals",
                    variable: "cognito-identity.amazonaws.com:aud",
                    values: ["us-east-1:12345678-dead-beef-cafe-123456790ab"],
                },
                {
                    test: "ForAnyValue:StringLike",
                    variable: "cognito-identity.amazonaws.com:amr",
                    values: ["authenticated"],
                },
            ],
        }],
    });
    const groupRoleRole = new aws.iam.Role("group_role", {
        name: "user-group-role",
        assumeRolePolicy: groupRole.then(groupRole => groupRole.json),
    });
    const mainUserGroup = new aws.cognito.UserGroup("main", {
        name: "user-group",
        userPoolId: main.id,
        description: "Managed by Pulumi",
        precedence: 42,
        roleArn: groupRoleRole.arn,
    });
    
    import pulumi
    import pulumi_aws as aws
    
    main = aws.cognito.UserPool("main", name="identity pool")
    group_role = aws.iam.get_policy_document(statements=[{
        "effect": "Allow",
        "principals": [{
            "type": "Federated",
            "identifiers": ["cognito-identity.amazonaws.com"],
        }],
        "actions": ["sts:AssumeRoleWithWebIdentity"],
        "conditions": [
            {
                "test": "StringEquals",
                "variable": "cognito-identity.amazonaws.com:aud",
                "values": ["us-east-1:12345678-dead-beef-cafe-123456790ab"],
            },
            {
                "test": "ForAnyValue:StringLike",
                "variable": "cognito-identity.amazonaws.com:amr",
                "values": ["authenticated"],
            },
        ],
    }])
    group_role_role = aws.iam.Role("group_role",
        name="user-group-role",
        assume_role_policy=group_role.json)
    main_user_group = aws.cognito.UserGroup("main",
        name="user-group",
        user_pool_id=main.id,
        description="Managed by Pulumi",
        precedence=42,
        role_arn=group_role_role.arn)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cognito"
    	"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 {
    		main, err := cognito.NewUserPool(ctx, "main", &cognito.UserPoolArgs{
    			Name: pulumi.String("identity pool"),
    		})
    		if err != nil {
    			return err
    		}
    		groupRole, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
    			Statements: []iam.GetPolicyDocumentStatement{
    				{
    					Effect: pulumi.StringRef("Allow"),
    					Principals: []iam.GetPolicyDocumentStatementPrincipal{
    						{
    							Type: "Federated",
    							Identifiers: []string{
    								"cognito-identity.amazonaws.com",
    							},
    						},
    					},
    					Actions: []string{
    						"sts:AssumeRoleWithWebIdentity",
    					},
    					Conditions: []iam.GetPolicyDocumentStatementCondition{
    						{
    							Test:     "StringEquals",
    							Variable: "cognito-identity.amazonaws.com:aud",
    							Values: []string{
    								"us-east-1:12345678-dead-beef-cafe-123456790ab",
    							},
    						},
    						{
    							Test:     "ForAnyValue:StringLike",
    							Variable: "cognito-identity.amazonaws.com:amr",
    							Values: []string{
    								"authenticated",
    							},
    						},
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		groupRoleRole, err := iam.NewRole(ctx, "group_role", &iam.RoleArgs{
    			Name:             pulumi.String("user-group-role"),
    			AssumeRolePolicy: pulumi.String(groupRole.Json),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = cognito.NewUserGroup(ctx, "main", &cognito.UserGroupArgs{
    			Name:        pulumi.String("user-group"),
    			UserPoolId:  main.ID(),
    			Description: pulumi.String("Managed by Pulumi"),
    			Precedence:  pulumi.Int(42),
    			RoleArn:     groupRoleRole.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 main = new Aws.Cognito.UserPool("main", new()
        {
            Name = "identity pool",
        });
    
        var groupRole = Aws.Iam.GetPolicyDocument.Invoke(new()
        {
            Statements = new[]
            {
                new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
                {
                    Effect = "Allow",
                    Principals = new[]
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                        {
                            Type = "Federated",
                            Identifiers = new[]
                            {
                                "cognito-identity.amazonaws.com",
                            },
                        },
                    },
                    Actions = new[]
                    {
                        "sts:AssumeRoleWithWebIdentity",
                    },
                    Conditions = new[]
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
                        {
                            Test = "StringEquals",
                            Variable = "cognito-identity.amazonaws.com:aud",
                            Values = new[]
                            {
                                "us-east-1:12345678-dead-beef-cafe-123456790ab",
                            },
                        },
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
                        {
                            Test = "ForAnyValue:StringLike",
                            Variable = "cognito-identity.amazonaws.com:amr",
                            Values = new[]
                            {
                                "authenticated",
                            },
                        },
                    },
                },
            },
        });
    
        var groupRoleRole = new Aws.Iam.Role("group_role", new()
        {
            Name = "user-group-role",
            AssumeRolePolicy = groupRole.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
        });
    
        var mainUserGroup = new Aws.Cognito.UserGroup("main", new()
        {
            Name = "user-group",
            UserPoolId = main.Id,
            Description = "Managed by Pulumi",
            Precedence = 42,
            RoleArn = groupRoleRole.Arn,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.cognito.UserPool;
    import com.pulumi.aws.cognito.UserPoolArgs;
    import com.pulumi.aws.iam.IamFunctions;
    import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
    import com.pulumi.aws.iam.Role;
    import com.pulumi.aws.iam.RoleArgs;
    import com.pulumi.aws.cognito.UserGroup;
    import com.pulumi.aws.cognito.UserGroupArgs;
    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 main = new UserPool("main", UserPoolArgs.builder()
                .name("identity pool")
                .build());
    
            final var groupRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                .statements(GetPolicyDocumentStatementArgs.builder()
                    .effect("Allow")
                    .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                        .type("Federated")
                        .identifiers("cognito-identity.amazonaws.com")
                        .build())
                    .actions("sts:AssumeRoleWithWebIdentity")
                    .conditions(                
                        GetPolicyDocumentStatementConditionArgs.builder()
                            .test("StringEquals")
                            .variable("cognito-identity.amazonaws.com:aud")
                            .values("us-east-1:12345678-dead-beef-cafe-123456790ab")
                            .build(),
                        GetPolicyDocumentStatementConditionArgs.builder()
                            .test("ForAnyValue:StringLike")
                            .variable("cognito-identity.amazonaws.com:amr")
                            .values("authenticated")
                            .build())
                    .build())
                .build());
    
            var groupRoleRole = new Role("groupRoleRole", RoleArgs.builder()
                .name("user-group-role")
                .assumeRolePolicy(groupRole.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json()))
                .build());
    
            var mainUserGroup = new UserGroup("mainUserGroup", UserGroupArgs.builder()
                .name("user-group")
                .userPoolId(main.id())
                .description("Managed by Pulumi")
                .precedence(42)
                .roleArn(groupRoleRole.arn())
                .build());
    
        }
    }
    
    resources:
      main:
        type: aws:cognito:UserPool
        properties:
          name: identity pool
      groupRoleRole:
        type: aws:iam:Role
        name: group_role
        properties:
          name: user-group-role
          assumeRolePolicy: ${groupRole.json}
      mainUserGroup:
        type: aws:cognito:UserGroup
        name: main
        properties:
          name: user-group
          userPoolId: ${main.id}
          description: Managed by Pulumi
          precedence: 42
          roleArn: ${groupRoleRole.arn}
    variables:
      groupRole:
        fn::invoke:
          Function: aws:iam:getPolicyDocument
          Arguments:
            statements:
              - effect: Allow
                principals:
                  - type: Federated
                    identifiers:
                      - cognito-identity.amazonaws.com
                actions:
                  - sts:AssumeRoleWithWebIdentity
                conditions:
                  - test: StringEquals
                    variable: cognito-identity.amazonaws.com:aud
                    values:
                      - us-east-1:12345678-dead-beef-cafe-123456790ab
                  - test: ForAnyValue:StringLike
                    variable: cognito-identity.amazonaws.com:amr
                    values:
                      - authenticated
    

    Create UserGroup Resource

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

    Constructor syntax

    new UserGroup(name: string, args: UserGroupArgs, opts?: CustomResourceOptions);
    @overload
    def UserGroup(resource_name: str,
                  args: UserGroupArgs,
                  opts: Optional[ResourceOptions] = None)
    
    @overload
    def UserGroup(resource_name: str,
                  opts: Optional[ResourceOptions] = None,
                  user_pool_id: Optional[str] = None,
                  description: Optional[str] = None,
                  name: Optional[str] = None,
                  precedence: Optional[int] = None,
                  role_arn: Optional[str] = None)
    func NewUserGroup(ctx *Context, name string, args UserGroupArgs, opts ...ResourceOption) (*UserGroup, error)
    public UserGroup(string name, UserGroupArgs args, CustomResourceOptions? opts = null)
    public UserGroup(String name, UserGroupArgs args)
    public UserGroup(String name, UserGroupArgs args, CustomResourceOptions options)
    
    type: aws:cognito:UserGroup
    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 UserGroupArgs
    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 UserGroupArgs
    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 UserGroupArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args UserGroupArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args UserGroupArgs
    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 userGroupResource = new Aws.Cognito.UserGroup("userGroupResource", new()
    {
        UserPoolId = "string",
        Description = "string",
        Name = "string",
        Precedence = 0,
        RoleArn = "string",
    });
    
    example, err := cognito.NewUserGroup(ctx, "userGroupResource", &cognito.UserGroupArgs{
    	UserPoolId:  pulumi.String("string"),
    	Description: pulumi.String("string"),
    	Name:        pulumi.String("string"),
    	Precedence:  pulumi.Int(0),
    	RoleArn:     pulumi.String("string"),
    })
    
    var userGroupResource = new UserGroup("userGroupResource", UserGroupArgs.builder()
        .userPoolId("string")
        .description("string")
        .name("string")
        .precedence(0)
        .roleArn("string")
        .build());
    
    user_group_resource = aws.cognito.UserGroup("userGroupResource",
        user_pool_id="string",
        description="string",
        name="string",
        precedence=0,
        role_arn="string")
    
    const userGroupResource = new aws.cognito.UserGroup("userGroupResource", {
        userPoolId: "string",
        description: "string",
        name: "string",
        precedence: 0,
        roleArn: "string",
    });
    
    type: aws:cognito:UserGroup
    properties:
        description: string
        name: string
        precedence: 0
        roleArn: string
        userPoolId: string
    

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

    UserPoolId string
    The user pool ID.
    Description string
    The description of the user group.
    Name string
    The name of the user group.
    Precedence int
    The precedence of the user group.
    RoleArn string
    The ARN of the IAM role to be associated with the user group.
    UserPoolId string
    The user pool ID.
    Description string
    The description of the user group.
    Name string
    The name of the user group.
    Precedence int
    The precedence of the user group.
    RoleArn string
    The ARN of the IAM role to be associated with the user group.
    userPoolId String
    The user pool ID.
    description String
    The description of the user group.
    name String
    The name of the user group.
    precedence Integer
    The precedence of the user group.
    roleArn String
    The ARN of the IAM role to be associated with the user group.
    userPoolId string
    The user pool ID.
    description string
    The description of the user group.
    name string
    The name of the user group.
    precedence number
    The precedence of the user group.
    roleArn string
    The ARN of the IAM role to be associated with the user group.
    user_pool_id str
    The user pool ID.
    description str
    The description of the user group.
    name str
    The name of the user group.
    precedence int
    The precedence of the user group.
    role_arn str
    The ARN of the IAM role to be associated with the user group.
    userPoolId String
    The user pool ID.
    description String
    The description of the user group.
    name String
    The name of the user group.
    precedence Number
    The precedence of the user group.
    roleArn String
    The ARN of the IAM role to be associated with the user group.

    Outputs

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

    Get an existing UserGroup 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?: UserGroupState, opts?: CustomResourceOptions): UserGroup
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            description: Optional[str] = None,
            name: Optional[str] = None,
            precedence: Optional[int] = None,
            role_arn: Optional[str] = None,
            user_pool_id: Optional[str] = None) -> UserGroup
    func GetUserGroup(ctx *Context, name string, id IDInput, state *UserGroupState, opts ...ResourceOption) (*UserGroup, error)
    public static UserGroup Get(string name, Input<string> id, UserGroupState? state, CustomResourceOptions? opts = null)
    public static UserGroup get(String name, Output<String> id, UserGroupState 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:
    Description string
    The description of the user group.
    Name string
    The name of the user group.
    Precedence int
    The precedence of the user group.
    RoleArn string
    The ARN of the IAM role to be associated with the user group.
    UserPoolId string
    The user pool ID.
    Description string
    The description of the user group.
    Name string
    The name of the user group.
    Precedence int
    The precedence of the user group.
    RoleArn string
    The ARN of the IAM role to be associated with the user group.
    UserPoolId string
    The user pool ID.
    description String
    The description of the user group.
    name String
    The name of the user group.
    precedence Integer
    The precedence of the user group.
    roleArn String
    The ARN of the IAM role to be associated with the user group.
    userPoolId String
    The user pool ID.
    description string
    The description of the user group.
    name string
    The name of the user group.
    precedence number
    The precedence of the user group.
    roleArn string
    The ARN of the IAM role to be associated with the user group.
    userPoolId string
    The user pool ID.
    description str
    The description of the user group.
    name str
    The name of the user group.
    precedence int
    The precedence of the user group.
    role_arn str
    The ARN of the IAM role to be associated with the user group.
    user_pool_id str
    The user pool ID.
    description String
    The description of the user group.
    name String
    The name of the user group.
    precedence Number
    The precedence of the user group.
    roleArn String
    The ARN of the IAM role to be associated with the user group.
    userPoolId String
    The user pool ID.

    Import

    Using pulumi import, import Cognito User Groups using the user_pool_id/name attributes concatenated. For example:

    $ pulumi import aws:cognito/userGroup:UserGroup group us-east-1_vG78M4goG/user-group
    

    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