UserGroup class

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: [{
        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"],
            },
        ],
        principals: [{
            type: "Federated",
            identifiers: ["cognito-identity.amazonaws.com"],
        }],
        effect: "Allow",
        actions: ["sts:AssumeRoleWithWebIdentity"],
    }],
});
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=[{
    "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"],
        },
    ],
    "principals": [{
        "type": "Federated",
        "identifiers": ["cognito-identity.amazonaws.com"],
    }],
    "effect": "Allow",
    "actions": ["sts:AssumeRoleWithWebIdentity"],
}])
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)
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
            {
                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",
                        },
                    },
                },
                Principals = new[]
                {
                    new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                    {
                        Type = "Federated",
                        Identifiers = new[]
                        {
                            "cognito-identity.amazonaws.com",
                        },
                    },
                },
                Effect = "Allow",
                Actions = new[]
                {
                    "sts:AssumeRoleWithWebIdentity",
                },
            },
        },
    });

    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 main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/cognito"
	"github.com/pulumi/pulumi-aws/sdk/v7/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{
				{
					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",
							},
						},
					},
					Principals: []iam.GetPolicyDocumentStatementPrincipal{
						{
							Type: "Federated",
							Identifiers: []string{
								"cognito-identity.amazonaws.com",
							},
						},
					},
					Effect: pulumi.StringRef("Allow"),
					Actions: []string{
						"sts:AssumeRoleWithWebIdentity",
					},
				},
			},
		}, 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().ToIDOutput().ToStringOutput(),
			Description: pulumi.String("Managed by Pulumi"),
			Precedence:  pulumi.Int(42),
			RoleArn:     groupRoleRole.Arn,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

data "aws_iam_getpolicydocument" "groupRole" {
  statements {
    conditions {
      test     = "StringEquals"
      variable = "cognito-identity.amazonaws.com:aud"
      values   = ["us-east-1:12345678-dead-beef-cafe-123456790ab"]
    }
    conditions {
      test     = "ForAnyValue:StringLike"
      variable = "cognito-identity.amazonaws.com:amr"
      values   = ["authenticated"]
    }
    principals {
      type        = "Federated"
      identifiers = ["cognito-identity.amazonaws.com"]
    }
    effect  = "Allow"
    actions = ["sts:AssumeRoleWithWebIdentity"]
  }
}

resource "aws_cognito_userpool" "main" {
  name = "identity pool"
}
resource "aws_iam_role" "group_role" {
  name               = "user-group-role"
  assume_role_policy = data.aws_iam_getpolicydocument.groupRole.json
}
resource "aws_cognito_usergroup" "main" {
  name         = "user-group"
  user_pool_id = aws_cognito_userpool.main.id
  description  = "Managed by Pulumi"
  precedence   = 42
  role_arn     = aws_iam_role.group_role.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.inputs.GetPolicyDocumentStatementArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementConditionArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
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.ArrayList;
import java.util.Arrays;
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()
                .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())
                .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                    .type("Federated")
                    .identifiers("cognito-identity.amazonaws.com")
                    .build())
                .effect("Allow")
                .actions("sts:AssumeRoleWithWebIdentity")
                .build())
            .build());

        var groupRoleRole = new Role("groupRoleRole", RoleArgs.builder()
            .name("user-group-role")
            .assumeRolePolicy(groupRole.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:
          - 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
            principals:
              - type: Federated
                identifiers:
                  - cognito-identity.amazonaws.com
            effect: Allow
            actions:
              - sts:AssumeRoleWithWebIdentity

Import

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

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

Constructors

UserGroup(String name, {UserGroupArgs? args, CustomResourceOptions? options})
Creates a new UserGroup. name The Pulumi resource name. args Arguments used to configure this UserGroup. The set of arguments for UserGroup. options Resource options controlling this resource's behavior.
UserGroup.reference(String urn)
Creates a typed reference to an existing UserGroup resource.

Properties

childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
description ↔ Output<String?>
The description of the user group.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
name ↔ Output<String>
The name of the user group.
latefinal
precedence ↔ Output<int?>
The precedence of the user group.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
roleArn ↔ Output<String?>
The ARN of the IAM role to be associated with the user group.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited
userPoolId ↔ Output<String>
The user pool ID.
latefinal

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {UserGroupState? state, CustomResourceOptions? options}) → UserGroup
Gets an existing UserGroup resource's state with the given name and id.