From cdef0f0cf24b2d2ffb37be9465c9f3737a323d00 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 9 May 2024 14:15:22 -0400 Subject: [PATCH 01/15] d/ cognito_user_pool --- .../service/cognitoidp/service_package_gen.go | 4 + .../cognitoidp/user_pool_data_source.go | 454 ++++++++++++++++++ .../cognitoidp/user_pool_data_source_test.go | 150 ++++++ .../docs/d/cognito_user_pool.html.markdown | 117 +++++ 4 files changed, 725 insertions(+) create mode 100644 internal/service/cognitoidp/user_pool_data_source.go create mode 100644 internal/service/cognitoidp/user_pool_data_source_test.go create mode 100644 website/docs/d/cognito_user_pool.html.markdown diff --git a/internal/service/cognitoidp/service_package_gen.go b/internal/service/cognitoidp/service_package_gen.go index 104d635d1bc..ef360bd118a 100644 --- a/internal/service/cognitoidp/service_package_gen.go +++ b/internal/service/cognitoidp/service_package_gen.go @@ -17,6 +17,10 @@ type servicePackage struct{} func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { return []*types.ServicePackageFrameworkDataSource{ + { + Factory: newDataSourceUserPool, + Name: "User Pool", + }, { Factory: newUserGroupDataSource, Name: "User Group", diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go new file mode 100644 index 00000000000..75c53658a39 --- /dev/null +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -0,0 +1,454 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package cognitoidp + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// @FrameworkDataSource("aws_cognito_user_group", name="User Pool") +func newDataSourceUserPool(context.Context) (datasource.DataSourceWithConfigure, error) { + return &dataSourceUserPool{}, nil +} + +const ( + DSNameUserPool = "User Pool Data Source" +) + +type dataSourceUserPool struct { + framework.DataSourceWithConfigure +} + +func (d *dataSourceUserPool) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name + resp.TypeName = "aws_cognito_user_pool" +} + +func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "arn": schema.StringAttribute{ + Computed: true, + }, + "auto_verified_attributes": schema.ListAttribute{ + Computed: true, + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + }, + "creation_date": schema.StringAttribute{ + Computed: true, + }, + "custom_domain": schema.StringAttribute{ + Computed: true, + }, + "deletion_protection": schema.StringAttribute{ + Computed: true, + }, + "domain": schema.StringAttribute{ + Computed: true, + }, + "email_verification_message": schema.StringAttribute{ + Computed: true, + }, + "email_verification_subject": schema.StringAttribute{ + Computed: true, + }, + "estimated_number_of_users": schema.Int64Attribute{ + Computed: true, + }, + "id": schema.StringAttribute{ + Required: true, + }, + "last_modified_date": schema.StringAttribute{ + Computed: true, + }, + "mfa_configuration": schema.StringAttribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Computed: true, + }, + "sms_authentication_message": schema.StringAttribute{ + Computed: true, + }, + "sms_configuration_failure": schema.StringAttribute{ + Computed: true, + }, + "sms_verification_message": schema.StringAttribute{ + Computed: true, + }, + "user_pool_tags": tftags.TagsAttributeComputedOnly(), + "username_attributes": schema.ListAttribute{ + Computed: true, + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + }, + }, + Blocks: map[string]schema.Block{ + "account_recovery_setting": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[accountRecoverySettingType](ctx), + NestedObject: schema.NestedBlockObject{ + Blocks: map[string]schema.Block{ + "recovery_mechanism": schema.ListNestedBlock{ + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Computed: true, + }, + "priority": schema.Int64Attribute{ + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "admin_create_user_config": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[adminCreateUserConfigType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "allow_admin_create_user_only": schema.BoolAttribute{ + Computed: true, + }, + "unused_account_validity_days": schema.Int64Attribute{ + Computed: true, + }, + }, + Blocks: map[string]schema.Block{ + "invite_message_template": schema.ListNestedBlock{ + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "email_message": schema.StringAttribute{ + Computed: true, + }, + "email_subject": schema.StringAttribute{ + Computed: true, + }, + "sms_message": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "device_configuration": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[deviceConfigurationType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "challenge_required_on_new_device": schema.BoolAttribute{ + Computed: true, + }, + "device_only_remembered_on_user_prompt": schema.BoolAttribute{ + Computed: true, + }, + }, + }, + }, + "email_configuration": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[emailConfigurationType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "configuration_set": schema.StringAttribute{ + Computed: true, + }, + "email_sending_account": schema.StringAttribute{ + Computed: true, + }, + "from": schema.StringAttribute{ + Computed: true, + }, + "reply_to_email_address": schema.StringAttribute{ + Computed: true, + }, + "source_arn": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + "lambda_config": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[lambdaConfigType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "create_auth_challenge": schema.StringAttribute{ + Computed: true, + }, + "custom_message": schema.StringAttribute{ + Computed: true, + }, + "define_auth_challenge": schema.StringAttribute{ + Computed: true, + }, + "kms_key_id": schema.StringAttribute{ + Computed: true, + }, + "post_authentication": schema.StringAttribute{ + Computed: true, + }, + "post_confirmation": schema.StringAttribute{ + Computed: true, + }, + "pre_authentication": schema.StringAttribute{ + Computed: true, + }, + "pre_sign_up": schema.StringAttribute{ + Computed: true, + }, + "pre_token_generation": schema.StringAttribute{ + Computed: true, + }, + "user_migration": schema.StringAttribute{ + Computed: true, + }, + "verify_auth_challenge_response": schema.StringAttribute{ + Computed: true, + }, + }, + Blocks: map[string]schema.Block{ + "custom_email_sender": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[customEmailSenderType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "lambda_arn": schema.StringAttribute{ + Computed: true, + }, + "lambda_version": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + "custom_sms_sender": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[customSMSSenderType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "lambda_arn": schema.StringAttribute{ + Computed: true, + }, + "lambda_version": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + "pre_token_generation_config": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[preTokenGenerationConfigType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "lambda_arn": schema.StringAttribute{ + Computed: true, + }, + "lambda_version": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "schema_attributes": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[schemaAttributeType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "attribute_data_type": schema.StringAttribute{ + Computed: true, + }, + "developer_only_attribute": schema.BoolAttribute{ + Computed: true, + }, + "mutable": schema.BoolAttribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Computed: true, + }, + "required": schema.BoolAttribute{ + Computed: true, + }, + }, + Blocks: map[string]schema.Block{ + "number_attribute_constraints": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[numberAttributeConstraintsType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "max_value": schema.StringAttribute{ + Computed: true, + }, + "min_value": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + "string_attribute_constraints": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[stringAttributeConstraintsType](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "max_length": schema.StringAttribute{ + Computed: true, + }, + "min_length": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func (d *dataSourceUserPool) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + conn := d.Meta().CognitoIDPConn(ctx) + + var data dataSourceUserPoolData + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + out, err := findUserPoolByID(ctx, conn, data.ID.ValueString()) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.CognitoIDP, create.ErrActionReading, DSNameUserPool, data.Name.String(), err), + err.Error(), + ) + return + } + + resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +type dataSourceUserPoolData struct { + AccountRecoverySetting fwtypes.ListNestedObjectValueOf[accountRecoverySettingType] `tfsdk:"account_recovery_setting"` + AdminCreateUserConfig fwtypes.ListNestedObjectValueOf[adminCreateUserConfigType] `tfsdk:"admin_create_user_config"` + Arn types.String `tfsdk:"arn"` + AutoVerifiedAttributes fwtypes.ListValueOf[types.String] `tfsdk:"auto_verified_attributes"` + CreationDate types.String `tfsdk:"creation_date"` + CustomDomain types.String `tfsdk:"custom_domain"` + DeletionProtection types.String `tfsdk:"deletion_protection"` + DeviceConfiguration fwtypes.ListNestedObjectValueOf[deviceConfigurationType] `tfsdk:"device_configuration"` + Domain types.String `tfsdk:"domain"` + EmailConfiguration fwtypes.ListNestedObjectValueOf[emailConfigurationType] `tfsdk:"email_configuration"` + EmailVerificationMessage types.String `tfsdk:"email_verification_message"` + EmailVerificationSubject types.String `tfsdk:"email_verification_subject"` + EstimatedNumberOfUsers types.Int64 `tfsdk:"estimated_number_of_users"` + ID types.String `tfsdk:"id"` + LambdaConfig fwtypes.ListNestedObjectValueOf[lambdaConfigType] `tfsdk:"lambda_config"` + LastModifiedDate types.String `tfsdk:"last_modified_date"` + MfaConfiguration types.String `tfsdk:"mfa_configuration"` + SchemaAttributes fwtypes.ListNestedObjectValueOf[schemaAttributeType] `tfsdk:"schema_attributes"` + Name types.String `tfsdk:"name"` + SmsAuthenticationMessage types.String `tfsdk:"sms_authentication_message"` + SmsConfigurationFailure types.String `tfsdk:"sms_configuration_failure"` + SmsVerificationMessage types.String `tfsdk:"sms_verification_message"` + UserPoolTags types.Map `tfsdk:"user_pool_tags"` + UsernameAttributes fwtypes.ListValueOf[types.String] `tfsdk:"username_attributes"` +} + +type accountRecoverySettingType struct { + RecoveryMechanism fwtypes.ListNestedObjectValueOf[recoveryMechanismType] `tfsdk:"recovery_mechanism"` +} + +type adminCreateUserConfigType struct { + AllowAdminCreateUserOnly types.Bool `tfsdk:"allow_admin_create_user_only"` + InviteMessageTemplate fwtypes.ListNestedObjectValueOf[inviteMessageTemplateType] `tfsdk:"invite_message_template"` + UnusedAccountValidityDays types.Int64 `tfsdk:"unused_account_validity_days"` +} + +type inviteMessageTemplateType struct { + EmailMessage types.String `tfsdk:"email_message"` + EmailSubject types.String `tfsdk:"email_subject"` + SmsMessage types.String `tfsdk:"sms_message"` +} + +type deviceConfigurationType struct { + ChallengeRequiredOnNewDevice types.Bool `tfsdk:"challenge_required_on_new_device"` + DeviceOnlyRememberedOnUserPrompt types.Bool `tfsdk:"device_only_remembered_on_user_prompt"` +} + +type emailConfigurationType struct { + ConfigurationSet types.String `tfsdk:"configuration_set"` + EmailSendingAccount types.String `tfsdk:"email_sending_account"` + From types.String `tfsdk:"from"` + ReplyToEmailAddress types.String `tfsdk:"reply_to_email_address"` + SourceArn types.String `tfsdk:"source_arn"` +} + +type lambdaConfigType struct { + CreateAuthChallenge types.String `tfsdk:"create_auth_challenge"` + CustomEmailSender fwtypes.ListNestedObjectValueOf[customEmailSenderType] `tfsdk:"custom_email_sender"` + CustomMessage types.String `tfsdk:"custom_message"` + CustomSMSSender fwtypes.ListNestedObjectValueOf[customSMSSenderType] `tfsdk:"custom_sms_sender"` + DefineAuthChallenge types.String `tfsdk:"define_auth_challenge"` + KmsKeyId types.String `tfsdk:"kms_key_id"` + PostAuthentication types.String `tfsdk:"post_authentication"` + PostConfirmation types.String `tfsdk:"post_confirmation"` + PreAuthentication types.String `tfsdk:"pre_authentication"` + PreSignUp types.String `tfsdk:"pre_sign_up"` + PreTokenGeneration types.String `tfsdk:"pre_token_generation"` + PreTokenGenerationConfig fwtypes.ListNestedObjectValueOf[preTokenGenerationConfigType] `tfsdk:"pre_token_generation_config"` + UserMigration types.String `tfsdk:"user_migration"` + VerifyAuthChallengeResponse types.String `tfsdk:"verify_auth_challenge_response"` +} + +type customEmailSenderType struct { + LambdaArn types.String `tfsdk:"lambda_arn"` + LambdaVersion types.String `tfsdk:"lambda_version"` +} + +type customSMSSenderType struct { + LambdaArn types.String `tfsdk:"lambda_arn"` + LambdaVersion types.String `tfsdk:"lambda_version"` +} + +type preTokenGenerationConfigType struct { + LambdaArn types.String `tfsdk:"lambda_arn"` + LambdaVersion types.String `tfsdk:"lambda_version"` +} + +type recoveryMechanismType struct { + Name types.String `tfsdk:"name"` + Priority types.Int64 `tfsdk:"priority"` +} + +type schemaAttributeType struct { + AttributeDataType types.String `tfsdk:"attribute_data_type"` + DeveloperOnlyAttribute types.Bool `tfsdk:"developer_only_attribute"` + Mutable types.Bool `tfsdk:"mutable"` + Name types.String `tfsdk:"name"` + NumberAttributeConstraints fwtypes.ListNestedObjectValueOf[numberAttributeConstraintsType] `tfsdk:"number_attribute_constraints"` + Required types.Bool `tfsdk:"required"` + StringAttributeConstraints fwtypes.ListNestedObjectValueOf[stringAttributeConstraintsType] `tfsdk:"string_attribute_constraints"` +} + +type numberAttributeConstraintsType struct { + MaxValue types.String `tfsdk:"max_value"` + MinValue types.String `tfsdk:"min_value"` +} + +type stringAttributeConstraintsType struct { + MaxLength types.String `tfsdk:"max_length"` + MinLength types.String `tfsdk:"min_length"` +} diff --git a/internal/service/cognitoidp/user_pool_data_source_test.go b/internal/service/cognitoidp/user_pool_data_source_test.go new file mode 100644 index 00000000000..280fd7bf3ec --- /dev/null +++ b/internal/service/cognitoidp/user_pool_data_source_test.go @@ -0,0 +1,150 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package cognitoidp_test + +import ( + "context" + "fmt" + "strconv" + "testing" + + "github.com/YakDriver/regexache" + "github.com/aws/aws-sdk-go/service/cognitoidentityprovider" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccCognitoIDPUserPoolDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + + var userpool cognitoidentityprovider.UserPoolType + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dataSourceName := "data.aws_cognito_user_pool.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + // acctest.PreCheckPartitionHasService(t, names.CognitoIDPServiceID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CognitoIDPServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckUserPoolDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccUserPoolDataSourceConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckUserPoolExists(ctx, dataSourceName, &userpool), + acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "cognito-idp", regexache.MustCompile(`userpool/.*`)), + resource.TestCheckResourceAttr(dataSourceName, "name", rName), + ), + }, + }, + }) +} + +func TestAccCognitoIDPUserPoolDataSource_schemaAttributes(t *testing.T) { + ctx := acctest.Context(t) + + var userpool cognitoidentityprovider.UserPoolType + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dataSourceName := "data.aws_cognito_user_pool.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + // acctest.PreCheckPartitionHasService(t, names.CognitoIDPServiceID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.CognitoIDPServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckUserPoolDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccUserPoolDataSourceConfig_schemaAttributes(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckUserPoolExists(ctx, dataSourceName, &userpool), + resource.TestCheckResourceAttr(dataSourceName, "name", rName), + testSchemaAttributes(ctx, dataSourceName), + ), + }, + }, + }) +} + +func testStateAttribute(atts map[string]string, attribute string, value string) bool { + if atts[attribute] != value { + return false + } + return true +} + +func testSchemaAttributes(ctx context.Context, n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + // Get the number of schema_attributes + numAttributesStr, ok := rs.Primary.Attributes["schema_attributes.#"] + if !ok { + return fmt.Errorf("schema_attributes not found in resource %s", n) + } + numAttributes, err := strconv.Atoi(numAttributesStr) + if err != nil { + return fmt.Errorf("error parsing schema_attributes.#: %s", err) + } + + // Loop through the schema_attributes and check the mutable key in each attribute + checksCompleted := map[string]bool{ + "email": false, + } + for i := 0; i < numAttributes; i++ { + // Get the attribute + attribute := fmt.Sprintf("schema_attributes.%d.name", i) + name, ok := rs.Primary.Attributes[attribute] + if name == "" || !ok { + return fmt.Errorf("attribute not found at %s", name) + } + if name == "email" { + if !testStateAttribute(rs.Primary.Attributes, fmt.Sprintf("schema_attributes.%d.mutable", i), "false") { + return fmt.Errorf("mutable is not false for attribute %v", name) + } + checksCompleted["email"] = true + } + } + for k, v := range checksCompleted { + if !v { + return fmt.Errorf("attribute %v not found in schema_attributes", k) + } + } + + return nil + } +} + +func testAccUserPoolDataSourceConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "aws_cognito_user_pool" "test" { + name = %[1]q +} + +data "aws_cognito_user_pool" "test" { + id = aws_cognito_user_pool.test.id +} +`, rName) +} + +func testAccUserPoolDataSourceConfig_schemaAttributes(rName string) string { + return acctest.ConfigCompose( + testAccUserPoolConfig_schemaAttributes(rName), + ` +data "aws_cognito_user_pool" "test" { + id = aws_cognito_user_pool.test.id +} +`) +} diff --git a/website/docs/d/cognito_user_pool.html.markdown b/website/docs/d/cognito_user_pool.html.markdown new file mode 100644 index 00000000000..5d93796b9a0 --- /dev/null +++ b/website/docs/d/cognito_user_pool.html.markdown @@ -0,0 +1,117 @@ +--- + +subcategory: "Cognito IDP (Identity Provider)" +layout: "aws" +page_title: "AWS: aws_cognito_user_pool" +description: |- + Terraform data source for managing an AWS Cognito User Pool. + +--- + +# Data Source: aws_cognito_user_pool + +Terraform data source for managing an AWS Cognito User Pool. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_cognito_user_pool" "example" { + id = "us-west-2_aaaaaaaaa" +} +``` + +## Argument Reference + +The following arguments are required: + +* `id` - (Required) The cognito pool id + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `arn` - ARN of the User Pool. +* [account_recovery_setting](#account-recover-setting) +* [admin_create_user_config](#admin-create-user-config +* `auto_verified_attributes` +* `creation_date` +* `custom_domain` +* `deletion_protection` +* [device_configuration](#device-configuration) +* `domain` +* [email_configuration](#email-configuration) +* `email_verification_message` +* `email_verification_subject` +* `estimated_number_of_users` +* [lambda_config](#lambda-config) +* `last_modified_date` +* `mfa_configuration` +* `name` +* [schema_attributes](#schema-attributes) +* `sms_authentication_message` +* `sms_configuration_failure` +* `sms_verification_message` +* `user_pool_tags` +* `username_attributes` + +### account recover setting + +* [recovery_mechanism](#recovery-mechanism) - Details about an individual recovery mechanism. + +### recovery mechanism +* `name` - Name of the recovery mechanism (e.g., email, phone number). +* `priority` - Priority of this mechanism in the recovery process (lower numbers are higher priority). + +### admin create user config + +* `allow_admin_create_user_only` - Whether only admins can create users. +* `unused_account_validity_days` - Number of days an unconfirmed user account remains valid. +* [invite_message_template](#invite-message-template) - Templates for invitation messages. + +### invite message template +* `email_message` - Email message content. +* `email_subject` - Email message subject. +* `sms_message` - SMS message content. + +### device configuration + +* `challenge_required_on_new_device` - Whether a challenge is required on new devices. +* `device_only_remembered_on_user_prompt` - Whether devices are only remembered if the user prompts it. + +### email configuration + +* `configuration_set` - Configuration set used for sending emails. +* `email_sending_account` - Email sending account. +* `from` - Email sender address. +* `reply_to_email_address` - Reply-to email address. +* `source_arn` - Source Amazon Resource Name (ARN) for emails. + +### lambda config +* [custom_email_sender](#lambda-function) - Configuration for a custom email sender Lambda function. + +* [custom_sms_sender](#lambda-function) - Configuration for a custom SMS sender Lambda function +* [pre_token_generation_config](#lambda-function) - Configuration for a Lambda function that executes before token generation. + +### lambda function +* `lambda_arn` - ARN of the Lambda function. +* `lambda_version` - Version of the Lambda function. + +### schema attributes + +* `attribute_data_type` - Data type of the attribute (e.g., string, number). +* `developer_only_attribute` - Whether the attribute is for developer use only. +* `mutable` - Whether the attribute can be changed after user creation. +* `name` - Name of the attribute. +* `required` - Whether the attribute is required during user registration. +* [number_attribute_constraints](#number-attribute-constraints) - Constraints for numeric attributes (if applicable). +* [string_attribute_constraints](#string-attribute-constraints) - Constraints for string attributes (if applicable). + +### number attribute constraints +* `max_value` - Maximum allowed value. +* `min_value` - Minimum allowed value. + +### string attribute constraints +* `max_length` - Maximum allowed length. +* `min_length` - Minimum allowed length. From 44dafec712f28f67a8a7da699004b99ef0a8b0e4 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 9 May 2024 14:19:38 -0400 Subject: [PATCH 02/15] :memo: changelog --- .changelog/37399.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/37399.txt diff --git a/.changelog/37399.txt b/.changelog/37399.txt new file mode 100644 index 00000000000..a92ef98950d --- /dev/null +++ b/.changelog/37399.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +aws_cognito_user_pool +``` From ca5b901caa3c88e5423df52f4de1b4089226f1e8 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 9 May 2024 14:28:48 -0400 Subject: [PATCH 03/15] docs and remove email verification deprecated params --- .../cognitoidp/user_pool_data_source.go | 8 --- .../docs/d/cognito_user_pool.html.markdown | 53 ++++++++++--------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go index 75c53658a39..086ad673e29 100644 --- a/internal/service/cognitoidp/user_pool_data_source.go +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -57,12 +57,6 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "domain": schema.StringAttribute{ Computed: true, }, - "email_verification_message": schema.StringAttribute{ - Computed: true, - }, - "email_verification_subject": schema.StringAttribute{ - Computed: true, - }, "estimated_number_of_users": schema.Int64Attribute{ Computed: true, }, @@ -351,8 +345,6 @@ type dataSourceUserPoolData struct { DeviceConfiguration fwtypes.ListNestedObjectValueOf[deviceConfigurationType] `tfsdk:"device_configuration"` Domain types.String `tfsdk:"domain"` EmailConfiguration fwtypes.ListNestedObjectValueOf[emailConfigurationType] `tfsdk:"email_configuration"` - EmailVerificationMessage types.String `tfsdk:"email_verification_message"` - EmailVerificationSubject types.String `tfsdk:"email_verification_subject"` EstimatedNumberOfUsers types.Int64 `tfsdk:"estimated_number_of_users"` ID types.String `tfsdk:"id"` LambdaConfig fwtypes.ListNestedObjectValueOf[lambdaConfigType] `tfsdk:"lambda_config"` diff --git a/website/docs/d/cognito_user_pool.html.markdown b/website/docs/d/cognito_user_pool.html.markdown index 5d93796b9a0..d10b6e3ce9e 100644 --- a/website/docs/d/cognito_user_pool.html.markdown +++ b/website/docs/d/cognito_user_pool.html.markdown @@ -32,35 +32,34 @@ The following arguments are required: This data source exports the following attributes in addition to the arguments above: -* `arn` - ARN of the User Pool. -* [account_recovery_setting](#account-recover-setting) -* [admin_create_user_config](#admin-create-user-config -* `auto_verified_attributes` -* `creation_date` -* `custom_domain` -* `deletion_protection` -* [device_configuration](#device-configuration) -* `domain` -* [email_configuration](#email-configuration) -* `email_verification_message` -* `email_verification_subject` -* `estimated_number_of_users` -* [lambda_config](#lambda-config) -* `last_modified_date` -* `mfa_configuration` -* `name` -* [schema_attributes](#schema-attributes) -* `sms_authentication_message` -* `sms_configuration_failure` -* `sms_verification_message` -* `user_pool_tags` -* `username_attributes` +* `arn` - ARN of the User Pool. +* [account_recovery_setting](#account-recover-setting) - The available verified method a user can use to recover their password when they call ForgotPassword. You can use this setting to define a preferred method when a user has more than one method available. With this setting, SMS doesn't qualify for a valid password recovery mechanism if the user also has SMS multi-factor authentication (MFA) activated. In the absence of this setting, Amazon Cognito uses the legacy behavior to determine the recovery method where SMS is preferred through email. +* [admin_create_user_config](#admin-create-user-config) - The configuration for AdminCreateUser requests. +* `auto_verified_attributes` - The attributes that are auto-verified in a user pool. +* `creation_date` - The date and time, in ISO 8601 format, when the item was created. +* `custom_domain` - A custom domain name that you provide to Amazon Cognito. This parameter applies only if you use a custom domain to host the sign-up and sign-in pages for your application. An example of a custom domain name might be auth.example.com. +* `deletion_protection` - When active, DeletionProtection prevents accidental deletion of your user pool. Before you can delete a user pool that you have protected against deletion, you must deactivate this feature. +* [device_configuration](#device-configuration) - The device-remembering configuration for a user pool. A null value indicates that you have deactivated device remembering in your user pool. +* `domain` - The domain prefix, if the user pool has a domain associated with it. +* [email_configuration](#email-configuration) - The email configuration of your user pool. The email configuration type sets your preferred sending method, AWS Region, and sender for messages from your user pool. +* `estimated_number_of_users` - A number estimating the size of the user pool. +* [lambda_config](#lambda-config) - The AWS Lambda triggers associated with the user pool. +* `last_modified_date` - The date and time, in ISO 8601 format, when the item was modified. +* `mfa_configuration` - Can be one of the following values: `OFF` | `ON` | `OPTIONAL` +* `name` - The name of the user pool. +* [schema_attributes](#schema-attributes) - A list of the user attributes and their properties in your user pool. The attribute schema contains standard attributes, custom attributes with a custom: prefix, and developer attributes with a dev: prefix. For more information, see User pool attributes. +* `sms_authentication_message` - The contents of the SMS authentication message. +* `sms_configuration_failure` - The reason why the SMS configuration can't send the messages to your users. +* `sms_verification_message` - The contents of the SMS authentication message. +* `user_pool_tags` - The tags that are assigned to the user pool. A tag is a label that you can apply to user pools to categorize and manage them in different ways, such as by purpose, owner, environment, or other criteria. +* `username_attributes` - Specifies whether a user can use an email address or phone number as a username when they sign up. ### account recover setting * [recovery_mechanism](#recovery-mechanism) - Details about an individual recovery mechanism. ### recovery mechanism + * `name` - Name of the recovery mechanism (e.g., email, phone number). * `priority` - Priority of this mechanism in the recovery process (lower numbers are higher priority). @@ -89,12 +88,14 @@ This data source exports the following attributes in addition to the arguments a * `source_arn` - Source Amazon Resource Name (ARN) for emails. ### lambda config + * [custom_email_sender](#lambda-function) - Configuration for a custom email sender Lambda function. * [custom_sms_sender](#lambda-function) - Configuration for a custom SMS sender Lambda function * [pre_token_generation_config](#lambda-function) - Configuration for a Lambda function that executes before token generation. ### lambda function + * `lambda_arn` - ARN of the Lambda function. * `lambda_version` - Version of the Lambda function. @@ -105,13 +106,15 @@ This data source exports the following attributes in addition to the arguments a * `mutable` - Whether the attribute can be changed after user creation. * `name` - Name of the attribute. * `required` - Whether the attribute is required during user registration. -* [number_attribute_constraints](#number-attribute-constraints) - Constraints for numeric attributes (if applicable). -* [string_attribute_constraints](#string-attribute-constraints) - Constraints for string attributes (if applicable). +* [number_attribute_constraints](#number-attribute-constraints) - Constraints for numeric attributes. +* [string_attribute_constraints](#string-attribute-constraints) - Constraints for string attributes. ### number attribute constraints + * `max_value` - Maximum allowed value. * `min_value` - Minimum allowed value. ### string attribute constraints + * `max_length` - Maximum allowed length. * `min_length` - Minimum allowed length. From b007cfc40447674d28dfa3a4852d188d5ae81835 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 9 May 2024 14:30:57 -0400 Subject: [PATCH 04/15] whitespace --- website/docs/d/cognito_user_pool.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/cognito_user_pool.html.markdown b/website/docs/d/cognito_user_pool.html.markdown index d10b6e3ce9e..ff2a95506a1 100644 --- a/website/docs/d/cognito_user_pool.html.markdown +++ b/website/docs/d/cognito_user_pool.html.markdown @@ -70,6 +70,7 @@ This data source exports the following attributes in addition to the arguments a * [invite_message_template](#invite-message-template) - Templates for invitation messages. ### invite message template + * `email_message` - Email message content. * `email_subject` - Email message subject. * `sms_message` - SMS message content. @@ -90,7 +91,6 @@ This data source exports the following attributes in addition to the arguments a ### lambda config * [custom_email_sender](#lambda-function) - Configuration for a custom email sender Lambda function. - * [custom_sms_sender](#lambda-function) - Configuration for a custom SMS sender Lambda function * [pre_token_generation_config](#lambda-function) - Configuration for a Lambda function that executes before token generation. From 9ee4306899ed3d10fc4fff7a475b8fa9ba9c50f2 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 9 May 2024 14:38:54 -0400 Subject: [PATCH 05/15] use names const --- internal/service/cognitoidp/user_pool_data_source.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go index 086ad673e29..26080780fd1 100644 --- a/internal/service/cognitoidp/user_pool_data_source.go +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -37,7 +37,7 @@ func (d *dataSourceUserPool) Metadata(_ context.Context, req datasource.Metadata func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - "arn": schema.StringAttribute{ + names.AttrARN: schema.StringAttribute{ Computed: true, }, "auto_verified_attributes": schema.ListAttribute{ @@ -60,7 +60,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "estimated_number_of_users": schema.Int64Attribute{ Computed: true, }, - "id": schema.StringAttribute{ + names.AttrID: schema.StringAttribute{ Required: true, }, "last_modified_date": schema.StringAttribute{ @@ -69,7 +69,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "mfa_configuration": schema.StringAttribute{ Computed: true, }, - "name": schema.StringAttribute{ + names.AttrName: schema.StringAttribute{ Computed: true, }, "sms_authentication_message": schema.StringAttribute{ From b5bebd8887e405b25eec3298f2a4f755f40fc414 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 9 May 2024 14:53:13 -0400 Subject: [PATCH 06/15] more consts --- internal/service/cognitoidp/user_pool_data_source.go | 6 +++--- internal/service/cognitoidp/user_pool_data_source_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go index 26080780fd1..e5492ca7d1a 100644 --- a/internal/service/cognitoidp/user_pool_data_source.go +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -96,7 +96,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "recovery_mechanism": schema.ListNestedBlock{ NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - "name": schema.StringAttribute{ + names.AttrName: schema.StringAttribute{ Computed: true, }, "priority": schema.Int64Attribute{ @@ -186,7 +186,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "define_auth_challenge": schema.StringAttribute{ Computed: true, }, - "kms_key_id": schema.StringAttribute{ + names.AttrKMSKeyID: schema.StringAttribute{ Computed: true, }, "post_authentication": schema.StringAttribute{ @@ -267,7 +267,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "mutable": schema.BoolAttribute{ Computed: true, }, - "name": schema.StringAttribute{ + names.AttrName: schema.StringAttribute{ Computed: true, }, "required": schema.BoolAttribute{ diff --git a/internal/service/cognitoidp/user_pool_data_source_test.go b/internal/service/cognitoidp/user_pool_data_source_test.go index 280fd7bf3ec..0fda89d6779 100644 --- a/internal/service/cognitoidp/user_pool_data_source_test.go +++ b/internal/service/cognitoidp/user_pool_data_source_test.go @@ -39,7 +39,7 @@ func TestAccCognitoIDPUserPoolDataSource_basic(t *testing.T) { Config: testAccUserPoolDataSourceConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckUserPoolExists(ctx, dataSourceName, &userpool), - acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "cognito-idp", regexache.MustCompile(`userpool/.*`)), + acctest.MatchResourceAttrRegionalARN(dataSourceName, names.AttrARN, "cognito-idp", regexache.MustCompile(`userpool/.*`)), resource.TestCheckResourceAttr(dataSourceName, "name", rName), ), }, @@ -67,7 +67,7 @@ func TestAccCognitoIDPUserPoolDataSource_schemaAttributes(t *testing.T) { Config: testAccUserPoolDataSourceConfig_schemaAttributes(rName), Check: resource.ComposeTestCheckFunc( testAccCheckUserPoolExists(ctx, dataSourceName, &userpool), - resource.TestCheckResourceAttr(dataSourceName, "name", rName), + resource.TestCheckResourceAttr(dataSourceName, names.AttrName, rName), testSchemaAttributes(ctx, dataSourceName), ), }, From 4a7202659d81e129774732ca02ad8029db78e16d Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Mon, 13 May 2024 13:28:10 -0400 Subject: [PATCH 07/15] :broom: fix make gen, simplify function --- .../cognitoidp/user_pool_data_source_test.go | 17 ++++------------- website/docs/d/cognito_user_pool.html.markdown | 2 -- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/internal/service/cognitoidp/user_pool_data_source_test.go b/internal/service/cognitoidp/user_pool_data_source_test.go index 0fda89d6779..50670941740 100644 --- a/internal/service/cognitoidp/user_pool_data_source_test.go +++ b/internal/service/cognitoidp/user_pool_data_source_test.go @@ -4,7 +4,6 @@ package cognitoidp_test import ( - "context" "fmt" "strconv" "testing" @@ -40,7 +39,7 @@ func TestAccCognitoIDPUserPoolDataSource_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckUserPoolExists(ctx, dataSourceName, &userpool), acctest.MatchResourceAttrRegionalARN(dataSourceName, names.AttrARN, "cognito-idp", regexache.MustCompile(`userpool/.*`)), - resource.TestCheckResourceAttr(dataSourceName, "name", rName), + resource.TestCheckResourceAttr(dataSourceName, names.AttrName, rName), ), }, }, @@ -57,7 +56,6 @@ func TestAccCognitoIDPUserPoolDataSource_schemaAttributes(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - // acctest.PreCheckPartitionHasService(t, names.CognitoIDPServiceID) }, ErrorCheck: acctest.ErrorCheck(t, names.CognitoIDPServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -68,21 +66,14 @@ func TestAccCognitoIDPUserPoolDataSource_schemaAttributes(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckUserPoolExists(ctx, dataSourceName, &userpool), resource.TestCheckResourceAttr(dataSourceName, names.AttrName, rName), - testSchemaAttributes(ctx, dataSourceName), + testSchemaAttributes(dataSourceName), ), }, }, }) } -func testStateAttribute(atts map[string]string, attribute string, value string) bool { - if atts[attribute] != value { - return false - } - return true -} - -func testSchemaAttributes(ctx context.Context, n string) resource.TestCheckFunc { +func testSchemaAttributes(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -111,7 +102,7 @@ func testSchemaAttributes(ctx context.Context, n string) resource.TestCheckFunc return fmt.Errorf("attribute not found at %s", name) } if name == "email" { - if !testStateAttribute(rs.Primary.Attributes, fmt.Sprintf("schema_attributes.%d.mutable", i), "false") { + if rs.Primary.Attributes[fmt.Sprintf("schema_attributes.%d.mutable", i)] != "false" { return fmt.Errorf("mutable is not false for attribute %v", name) } checksCompleted["email"] = true diff --git a/website/docs/d/cognito_user_pool.html.markdown b/website/docs/d/cognito_user_pool.html.markdown index ff2a95506a1..9da0585ff50 100644 --- a/website/docs/d/cognito_user_pool.html.markdown +++ b/website/docs/d/cognito_user_pool.html.markdown @@ -1,11 +1,9 @@ --- - subcategory: "Cognito IDP (Identity Provider)" layout: "aws" page_title: "AWS: aws_cognito_user_pool" description: |- Terraform data source for managing an AWS Cognito User Pool. - --- # Data Source: aws_cognito_user_pool From c5d4bed5dda430d3a64fac647382f0278f492101 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Mon, 13 May 2024 13:28:47 -0400 Subject: [PATCH 08/15] remove extra whitespace --- internal/service/cognitoidp/user_pool_data_source_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/cognitoidp/user_pool_data_source_test.go b/internal/service/cognitoidp/user_pool_data_source_test.go index 50670941740..6b85fe717ac 100644 --- a/internal/service/cognitoidp/user_pool_data_source_test.go +++ b/internal/service/cognitoidp/user_pool_data_source_test.go @@ -14,7 +14,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/names" ) From 5bde613db2c927b290b253e689a605fb58844446 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Mon, 13 May 2024 13:44:40 -0400 Subject: [PATCH 09/15] name const --- internal/service/cognitoidp/user_pool_data_source.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go index e5492ca7d1a..36d65712ea1 100644 --- a/internal/service/cognitoidp/user_pool_data_source.go +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -45,7 +45,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe CustomType: fwtypes.ListOfStringType, ElementType: types.StringType, }, - "creation_date": schema.StringAttribute{ + names.AttrCreationDate: schema.StringAttribute{ Computed: true, }, "custom_domain": schema.StringAttribute{ @@ -54,7 +54,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "deletion_protection": schema.StringAttribute{ Computed: true, }, - "domain": schema.StringAttribute{ + names.AttrDomain: schema.StringAttribute{ Computed: true, }, "estimated_number_of_users": schema.Int64Attribute{ @@ -99,7 +99,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe names.AttrName: schema.StringAttribute{ Computed: true, }, - "priority": schema.Int64Attribute{ + names.AttrPriority: schema.Int64Attribute{ Computed: true, }, }, From a22bf7aa917a5e50b3b6125661b7252db4645931 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:04:31 -0400 Subject: [PATCH 10/15] cognito v2 migration --- internal/service/cognitoidp/user_pool_data_source.go | 2 +- internal/service/cognitoidp/user_pool_data_source_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go index 36d65712ea1..adf14947a56 100644 --- a/internal/service/cognitoidp/user_pool_data_source.go +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -309,7 +309,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe } func (d *dataSourceUserPool) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - conn := d.Meta().CognitoIDPConn(ctx) + conn := d.Meta().CognitoIDPClient(ctx) var data dataSourceUserPoolData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) diff --git a/internal/service/cognitoidp/user_pool_data_source_test.go b/internal/service/cognitoidp/user_pool_data_source_test.go index 6b85fe717ac..8d8492a4e50 100644 --- a/internal/service/cognitoidp/user_pool_data_source_test.go +++ b/internal/service/cognitoidp/user_pool_data_source_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/cognitoidentityprovider" + awsTypes "github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -20,7 +20,7 @@ import ( func TestAccCognitoIDPUserPoolDataSource_basic(t *testing.T) { ctx := acctest.Context(t) - var userpool cognitoidentityprovider.UserPoolType + var userpool awsTypes.UserPoolType rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) dataSourceName := "data.aws_cognito_user_pool.test" @@ -48,7 +48,7 @@ func TestAccCognitoIDPUserPoolDataSource_basic(t *testing.T) { func TestAccCognitoIDPUserPoolDataSource_schemaAttributes(t *testing.T) { ctx := acctest.Context(t) - var userpool cognitoidentityprovider.UserPoolType + var userpool awsTypes.UserPoolType rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) dataSourceName := "data.aws_cognito_user_pool.test" From 9653a193e3d44ec20d196629221f149913b62635 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:26:25 -0400 Subject: [PATCH 11/15] semgrep --- internal/service/cognitoidp/user_pool_data_source.go | 2 +- internal/service/cognitoidp/user_pool_data_source_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go index adf14947a56..9efe568bb58 100644 --- a/internal/service/cognitoidp/user_pool_data_source.go +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -51,7 +51,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "custom_domain": schema.StringAttribute{ Computed: true, }, - "deletion_protection": schema.StringAttribute{ + names.AttrDeletionProtection: schema.StringAttribute{ Computed: true, }, names.AttrDomain: schema.StringAttribute{ diff --git a/internal/service/cognitoidp/user_pool_data_source_test.go b/internal/service/cognitoidp/user_pool_data_source_test.go index 8d8492a4e50..b0529f84c7e 100644 --- a/internal/service/cognitoidp/user_pool_data_source_test.go +++ b/internal/service/cognitoidp/user_pool_data_source_test.go @@ -91,7 +91,7 @@ func testSchemaAttributes(n string) resource.TestCheckFunc { // Loop through the schema_attributes and check the mutable key in each attribute checksCompleted := map[string]bool{ - "email": false, + names.AttrEmail: false, } for i := 0; i < numAttributes; i++ { // Get the attribute @@ -100,11 +100,11 @@ func testSchemaAttributes(n string) resource.TestCheckFunc { if name == "" || !ok { return fmt.Errorf("attribute not found at %s", name) } - if name == "email" { + if name == names.AttrEmail { if rs.Primary.Attributes[fmt.Sprintf("schema_attributes.%d.mutable", i)] != "false" { return fmt.Errorf("mutable is not false for attribute %v", name) } - checksCompleted["email"] = true + checksCompleted[names.AttrEmail] = true } } for k, v := range checksCompleted { From 345ec7e67d4cc6335f0b3eaa8dde97123039bd2c Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:54:25 -0400 Subject: [PATCH 12/15] more consts to fix semgrep --- internal/service/cognitoidp/user_pool_data_source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/cognitoidp/user_pool_data_source_test.go b/internal/service/cognitoidp/user_pool_data_source_test.go index b0529f84c7e..219db601e98 100644 --- a/internal/service/cognitoidp/user_pool_data_source_test.go +++ b/internal/service/cognitoidp/user_pool_data_source_test.go @@ -101,7 +101,7 @@ func testSchemaAttributes(n string) resource.TestCheckFunc { return fmt.Errorf("attribute not found at %s", name) } if name == names.AttrEmail { - if rs.Primary.Attributes[fmt.Sprintf("schema_attributes.%d.mutable", i)] != "false" { + if rs.Primary.Attributes[fmt.Sprintf("schema_attributes.%d.mutable", i)] != acctest.CtFalse { return fmt.Errorf("mutable is not false for attribute %v", name) } checksCompleted[names.AttrEmail] = true From 511dbe9678102f2263d053a171d1648f2c05fbe3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 28 Jun 2024 15:09:19 -0400 Subject: [PATCH 13/15] d/aws_cognito_user_pool: Add 'user_pool_id' argument. --- .../service/cognitoidp/service_package_gen.go | 8 +-- .../cognitoidp/user_pool_data_source.go | 58 +++++++++---------- .../cognitoidp/user_pool_data_source_test.go | 4 +- .../docs/d/cognito_user_pool.html.markdown | 4 +- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/internal/service/cognitoidp/service_package_gen.go b/internal/service/cognitoidp/service_package_gen.go index 4985efef176..35efd7838b4 100644 --- a/internal/service/cognitoidp/service_package_gen.go +++ b/internal/service/cognitoidp/service_package_gen.go @@ -16,10 +16,6 @@ type servicePackage struct{} func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { return []*types.ServicePackageFrameworkDataSource{ - { - Factory: newDataSourceUserPool, - Name: "User Pool", - }, { Factory: newUserGroupDataSource, Name: "User Group", @@ -28,6 +24,10 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv Factory: newUserGroupsDataSource, Name: "User Groups", }, + { + Factory: newUserPoolDataSource, + Name: "User Pool", + }, } } diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go index 9efe568bb58..e27bf15b2e9 100644 --- a/internal/service/cognitoidp/user_pool_data_source.go +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -5,11 +5,11 @@ package cognitoidp import ( "context" + "fmt" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/framework" "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" @@ -18,24 +18,20 @@ import ( ) // @FrameworkDataSource("aws_cognito_user_group", name="User Pool") -func newDataSourceUserPool(context.Context) (datasource.DataSourceWithConfigure, error) { - return &dataSourceUserPool{}, nil +func newUserPoolDataSource(context.Context) (datasource.DataSourceWithConfigure, error) { + return &userPoolDataSource{}, nil } -const ( - DSNameUserPool = "User Pool Data Source" -) - -type dataSourceUserPool struct { +type userPoolDataSource struct { framework.DataSourceWithConfigure } -func (d *dataSourceUserPool) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name - resp.TypeName = "aws_cognito_user_pool" +func (*userPoolDataSource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name + response.TypeName = "aws_cognito_user_pool" } -func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ +func (d *userPoolDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) { + response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ names.AttrARN: schema.StringAttribute{ Computed: true, @@ -60,9 +56,7 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "estimated_number_of_users": schema.Int64Attribute{ Computed: true, }, - names.AttrID: schema.StringAttribute{ - Required: true, - }, + names.AttrID: framework.IDAttribute(), "last_modified_date": schema.StringAttribute{ Computed: true, }, @@ -81,6 +75,9 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe "sms_verification_message": schema.StringAttribute{ Computed: true, }, + "user_pool_id": schema.StringAttribute{ + Required: true, + }, "user_pool_tags": tftags.TagsAttributeComputedOnly(), "username_attributes": schema.ListAttribute{ Computed: true, @@ -308,33 +305,33 @@ func (d *dataSourceUserPool) Schema(ctx context.Context, req datasource.SchemaRe } } -func (d *dataSourceUserPool) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - conn := d.Meta().CognitoIDPClient(ctx) - - var data dataSourceUserPoolData - resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { +func (d *userPoolDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { + var data userPoolDataSourceModel + response.Diagnostics.Append(request.Config.Get(ctx, &data)...) + if response.Diagnostics.HasError() { return } - out, err := findUserPoolByID(ctx, conn, data.ID.ValueString()) + conn := d.Meta().CognitoIDPClient(ctx) + + userPoolID := data.UserPoolID.ValueString() + output, err := findUserPoolByID(ctx, conn, userPoolID) + if err != nil { - resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.CognitoIDP, create.ErrActionReading, DSNameUserPool, data.Name.String(), err), - err.Error(), - ) + response.Diagnostics.AddError(fmt.Sprintf("reading Cognito User Pool (%s)", userPoolID), err.Error()) + return } - resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...) - if resp.Diagnostics.HasError() { + response.Diagnostics.Append(flex.Flatten(ctx, output, &data)...) + if response.Diagnostics.HasError() { return } - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } -type dataSourceUserPoolData struct { +type userPoolDataSourceModel struct { AccountRecoverySetting fwtypes.ListNestedObjectValueOf[accountRecoverySettingType] `tfsdk:"account_recovery_setting"` AdminCreateUserConfig fwtypes.ListNestedObjectValueOf[adminCreateUserConfigType] `tfsdk:"admin_create_user_config"` Arn types.String `tfsdk:"arn"` @@ -355,6 +352,7 @@ type dataSourceUserPoolData struct { SmsAuthenticationMessage types.String `tfsdk:"sms_authentication_message"` SmsConfigurationFailure types.String `tfsdk:"sms_configuration_failure"` SmsVerificationMessage types.String `tfsdk:"sms_verification_message"` + UserPoolID types.String `tfsdk:"user_pool_id"` UserPoolTags types.Map `tfsdk:"user_pool_tags"` UsernameAttributes fwtypes.ListValueOf[types.String] `tfsdk:"username_attributes"` } diff --git a/internal/service/cognitoidp/user_pool_data_source_test.go b/internal/service/cognitoidp/user_pool_data_source_test.go index 219db601e98..e8f40fc1cd8 100644 --- a/internal/service/cognitoidp/user_pool_data_source_test.go +++ b/internal/service/cognitoidp/user_pool_data_source_test.go @@ -124,7 +124,7 @@ resource "aws_cognito_user_pool" "test" { } data "aws_cognito_user_pool" "test" { - id = aws_cognito_user_pool.test.id + user_pool_id = aws_cognito_user_pool.test.id } `, rName) } @@ -134,7 +134,7 @@ func testAccUserPoolDataSourceConfig_schemaAttributes(rName string) string { testAccUserPoolConfig_schemaAttributes(rName), ` data "aws_cognito_user_pool" "test" { - id = aws_cognito_user_pool.test.id + user_pool_id = aws_cognito_user_pool.test.id } `) } diff --git a/website/docs/d/cognito_user_pool.html.markdown b/website/docs/d/cognito_user_pool.html.markdown index 9da0585ff50..6f2c959d0f2 100644 --- a/website/docs/d/cognito_user_pool.html.markdown +++ b/website/docs/d/cognito_user_pool.html.markdown @@ -16,7 +16,7 @@ Terraform data source for managing an AWS Cognito User Pool. ```terraform data "aws_cognito_user_pool" "example" { - id = "us-west-2_aaaaaaaaa" + user_pool_id = "us-west-2_aaaaaaaaa" } ``` @@ -24,7 +24,7 @@ data "aws_cognito_user_pool" "example" { The following arguments are required: -* `id` - (Required) The cognito pool id +* `user_pool_id` - (Required) The cognito pool ID ## Attribute Reference From 35b66031a62567b8317eef48dd17f4f8fd1bce76 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 28 Jun 2024 15:33:58 -0400 Subject: [PATCH 14/15] d/aws_cognito_user_pool: ListAttribute for Computed, not ListNestedBlock. --- .../cognitoidp/user_pool_data_source.go | 414 ++++++------------ 1 file changed, 122 insertions(+), 292 deletions(-) diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go index e27bf15b2e9..7c0e7dd70d5 100644 --- a/internal/service/cognitoidp/user_pool_data_source.go +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -7,11 +7,12 @@ import ( "context" "fmt" + "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/framework" - "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/names" @@ -33,16 +34,31 @@ func (*userPoolDataSource) Metadata(_ context.Context, request datasource.Metada func (d *userPoolDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) { response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ + "account_recovery_setting": schema.ListAttribute{ + CustomType: fwtypes.NewListNestedObjectTypeOf[accountRecoverySettingTypeModel](ctx), + Computed: true, + ElementType: types.ObjectType{ + AttrTypes: fwtypes.AttributeTypesMust[accountRecoverySettingTypeModel](ctx), + }, + }, + "admin_create_user_config": schema.ListAttribute{ + CustomType: fwtypes.NewListNestedObjectTypeOf[adminCreateUserConfigTypeModel](ctx), + Computed: true, + ElementType: types.ObjectType{ + AttrTypes: fwtypes.AttributeTypesMust[adminCreateUserConfigTypeModel](ctx), + }, + }, names.AttrARN: schema.StringAttribute{ Computed: true, }, "auto_verified_attributes": schema.ListAttribute{ - Computed: true, CustomType: fwtypes.ListOfStringType, ElementType: types.StringType, + Computed: true, }, names.AttrCreationDate: schema.StringAttribute{ - Computed: true, + CustomType: timetypes.RFC3339Type{}, + Computed: true, }, "custom_domain": schema.StringAttribute{ Computed: true, @@ -50,15 +66,37 @@ func (d *userPoolDataSource) Schema(ctx context.Context, request datasource.Sche names.AttrDeletionProtection: schema.StringAttribute{ Computed: true, }, + "device_configuration": schema.ListAttribute{ + CustomType: fwtypes.NewListNestedObjectTypeOf[deviceConfigurationTypeModel](ctx), + Computed: true, + ElementType: types.ObjectType{ + AttrTypes: fwtypes.AttributeTypesMust[deviceConfigurationTypeModel](ctx), + }, + }, names.AttrDomain: schema.StringAttribute{ Computed: true, }, + "email_configuration": schema.ListAttribute{ + CustomType: fwtypes.NewListNestedObjectTypeOf[emailConfigurationTypeModel](ctx), + Computed: true, + ElementType: types.ObjectType{ + AttrTypes: fwtypes.AttributeTypesMust[emailConfigurationTypeModel](ctx), + }, + }, "estimated_number_of_users": schema.Int64Attribute{ Computed: true, }, names.AttrID: framework.IDAttribute(), + "lambda_config": schema.ListAttribute{ + CustomType: fwtypes.NewListNestedObjectTypeOf[lambdaConfigTypeModel](ctx), + Computed: true, + ElementType: types.ObjectType{ + AttrTypes: fwtypes.AttributeTypesMust[lambdaConfigTypeModel](ctx), + }, + }, "last_modified_date": schema.StringAttribute{ - Computed: true, + CustomType: timetypes.RFC3339Type{}, + Computed: true, }, "mfa_configuration": schema.StringAttribute{ Computed: true, @@ -66,6 +104,13 @@ func (d *userPoolDataSource) Schema(ctx context.Context, request datasource.Sche names.AttrName: schema.StringAttribute{ Computed: true, }, + "schema_attributes": schema.ListAttribute{ + CustomType: fwtypes.NewListNestedObjectTypeOf[schemaAttributeTypeModel](ctx), + Computed: true, + ElementType: types.ObjectType{ + AttrTypes: fwtypes.AttributeTypesMust[schemaAttributeTypeModel](ctx), + }, + }, "sms_authentication_message": schema.StringAttribute{ Computed: true, }, @@ -85,223 +130,6 @@ func (d *userPoolDataSource) Schema(ctx context.Context, request datasource.Sche ElementType: types.StringType, }, }, - Blocks: map[string]schema.Block{ - "account_recovery_setting": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[accountRecoverySettingType](ctx), - NestedObject: schema.NestedBlockObject{ - Blocks: map[string]schema.Block{ - "recovery_mechanism": schema.ListNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - names.AttrName: schema.StringAttribute{ - Computed: true, - }, - names.AttrPriority: schema.Int64Attribute{ - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "admin_create_user_config": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[adminCreateUserConfigType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "allow_admin_create_user_only": schema.BoolAttribute{ - Computed: true, - }, - "unused_account_validity_days": schema.Int64Attribute{ - Computed: true, - }, - }, - Blocks: map[string]schema.Block{ - "invite_message_template": schema.ListNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "email_message": schema.StringAttribute{ - Computed: true, - }, - "email_subject": schema.StringAttribute{ - Computed: true, - }, - "sms_message": schema.StringAttribute{ - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "device_configuration": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[deviceConfigurationType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "challenge_required_on_new_device": schema.BoolAttribute{ - Computed: true, - }, - "device_only_remembered_on_user_prompt": schema.BoolAttribute{ - Computed: true, - }, - }, - }, - }, - "email_configuration": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[emailConfigurationType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "configuration_set": schema.StringAttribute{ - Computed: true, - }, - "email_sending_account": schema.StringAttribute{ - Computed: true, - }, - "from": schema.StringAttribute{ - Computed: true, - }, - "reply_to_email_address": schema.StringAttribute{ - Computed: true, - }, - "source_arn": schema.StringAttribute{ - Computed: true, - }, - }, - }, - }, - "lambda_config": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[lambdaConfigType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "create_auth_challenge": schema.StringAttribute{ - Computed: true, - }, - "custom_message": schema.StringAttribute{ - Computed: true, - }, - "define_auth_challenge": schema.StringAttribute{ - Computed: true, - }, - names.AttrKMSKeyID: schema.StringAttribute{ - Computed: true, - }, - "post_authentication": schema.StringAttribute{ - Computed: true, - }, - "post_confirmation": schema.StringAttribute{ - Computed: true, - }, - "pre_authentication": schema.StringAttribute{ - Computed: true, - }, - "pre_sign_up": schema.StringAttribute{ - Computed: true, - }, - "pre_token_generation": schema.StringAttribute{ - Computed: true, - }, - "user_migration": schema.StringAttribute{ - Computed: true, - }, - "verify_auth_challenge_response": schema.StringAttribute{ - Computed: true, - }, - }, - Blocks: map[string]schema.Block{ - "custom_email_sender": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[customEmailSenderType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "lambda_arn": schema.StringAttribute{ - Computed: true, - }, - "lambda_version": schema.StringAttribute{ - Computed: true, - }, - }, - }, - }, - "custom_sms_sender": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[customSMSSenderType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "lambda_arn": schema.StringAttribute{ - Computed: true, - }, - "lambda_version": schema.StringAttribute{ - Computed: true, - }, - }, - }, - }, - "pre_token_generation_config": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[preTokenGenerationConfigType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "lambda_arn": schema.StringAttribute{ - Computed: true, - }, - "lambda_version": schema.StringAttribute{ - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "schema_attributes": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[schemaAttributeType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "attribute_data_type": schema.StringAttribute{ - Computed: true, - }, - "developer_only_attribute": schema.BoolAttribute{ - Computed: true, - }, - "mutable": schema.BoolAttribute{ - Computed: true, - }, - names.AttrName: schema.StringAttribute{ - Computed: true, - }, - "required": schema.BoolAttribute{ - Computed: true, - }, - }, - Blocks: map[string]schema.Block{ - "number_attribute_constraints": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[numberAttributeConstraintsType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "max_value": schema.StringAttribute{ - Computed: true, - }, - "min_value": schema.StringAttribute{ - Computed: true, - }, - }, - }, - }, - "string_attribute_constraints": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[stringAttributeConstraintsType](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "max_length": schema.StringAttribute{ - Computed: true, - }, - "min_length": schema.StringAttribute{ - Computed: true, - }, - }, - }, - }, - }, - }, - }, - }, } } @@ -323,122 +151,124 @@ func (d *userPoolDataSource) Read(ctx context.Context, request datasource.ReadRe return } - response.Diagnostics.Append(flex.Flatten(ctx, output, &data)...) + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data)...) if response.Diagnostics.HasError() { return } + data.ID = fwflex.StringValueToFramework(ctx, userPoolID) + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } type userPoolDataSourceModel struct { - AccountRecoverySetting fwtypes.ListNestedObjectValueOf[accountRecoverySettingType] `tfsdk:"account_recovery_setting"` - AdminCreateUserConfig fwtypes.ListNestedObjectValueOf[adminCreateUserConfigType] `tfsdk:"admin_create_user_config"` - Arn types.String `tfsdk:"arn"` - AutoVerifiedAttributes fwtypes.ListValueOf[types.String] `tfsdk:"auto_verified_attributes"` - CreationDate types.String `tfsdk:"creation_date"` - CustomDomain types.String `tfsdk:"custom_domain"` - DeletionProtection types.String `tfsdk:"deletion_protection"` - DeviceConfiguration fwtypes.ListNestedObjectValueOf[deviceConfigurationType] `tfsdk:"device_configuration"` - Domain types.String `tfsdk:"domain"` - EmailConfiguration fwtypes.ListNestedObjectValueOf[emailConfigurationType] `tfsdk:"email_configuration"` - EstimatedNumberOfUsers types.Int64 `tfsdk:"estimated_number_of_users"` - ID types.String `tfsdk:"id"` - LambdaConfig fwtypes.ListNestedObjectValueOf[lambdaConfigType] `tfsdk:"lambda_config"` - LastModifiedDate types.String `tfsdk:"last_modified_date"` - MfaConfiguration types.String `tfsdk:"mfa_configuration"` - SchemaAttributes fwtypes.ListNestedObjectValueOf[schemaAttributeType] `tfsdk:"schema_attributes"` - Name types.String `tfsdk:"name"` - SmsAuthenticationMessage types.String `tfsdk:"sms_authentication_message"` - SmsConfigurationFailure types.String `tfsdk:"sms_configuration_failure"` - SmsVerificationMessage types.String `tfsdk:"sms_verification_message"` - UserPoolID types.String `tfsdk:"user_pool_id"` - UserPoolTags types.Map `tfsdk:"user_pool_tags"` - UsernameAttributes fwtypes.ListValueOf[types.String] `tfsdk:"username_attributes"` + AccountRecoverySetting fwtypes.ListNestedObjectValueOf[accountRecoverySettingTypeModel] `tfsdk:"account_recovery_setting"` + AdminCreateUserConfig fwtypes.ListNestedObjectValueOf[adminCreateUserConfigTypeModel] `tfsdk:"admin_create_user_config"` + ARN types.String `tfsdk:"arn"` + AutoVerifiedAttributes fwtypes.ListValueOf[types.String] `tfsdk:"auto_verified_attributes"` + CreationDate timetypes.RFC3339 `tfsdk:"creation_date"` + CustomDomain types.String `tfsdk:"custom_domain"` + DeletionProtection types.String `tfsdk:"deletion_protection"` + DeviceConfiguration fwtypes.ListNestedObjectValueOf[deviceConfigurationTypeModel] `tfsdk:"device_configuration"` + Domain types.String `tfsdk:"domain"` + EmailConfiguration fwtypes.ListNestedObjectValueOf[emailConfigurationTypeModel] `tfsdk:"email_configuration"` + EstimatedNumberOfUsers types.Int64 `tfsdk:"estimated_number_of_users"` + ID types.String `tfsdk:"id"` + LambdaConfig fwtypes.ListNestedObjectValueOf[lambdaConfigTypeModel] `tfsdk:"lambda_config"` + LastModifiedDate timetypes.RFC3339 `tfsdk:"last_modified_date"` + MFAConfiguration types.String `tfsdk:"mfa_configuration"` + Name types.String `tfsdk:"name"` + SchemaAttributes fwtypes.ListNestedObjectValueOf[schemaAttributeTypeModel] `tfsdk:"schema_attributes"` + SMSAuthenticationMessage types.String `tfsdk:"sms_authentication_message"` + SMSConfigurationFailure types.String `tfsdk:"sms_configuration_failure"` + SMSVerificationMessage types.String `tfsdk:"sms_verification_message"` + UserPoolID types.String `tfsdk:"user_pool_id"` + UserPoolTags types.Map `tfsdk:"user_pool_tags"` + UsernameAttributes fwtypes.ListValueOf[types.String] `tfsdk:"username_attributes"` +} + +type accountRecoverySettingTypeModel struct { + RecoveryMechanism fwtypes.ListNestedObjectValueOf[recoveryOptionTypeModel] `tfsdk:"recovery_mechanism"` } -type accountRecoverySettingType struct { - RecoveryMechanism fwtypes.ListNestedObjectValueOf[recoveryMechanismType] `tfsdk:"recovery_mechanism"` +type recoveryOptionTypeModel struct { + Name types.String `tfsdk:"name"` + Priority types.Int64 `tfsdk:"priority"` } -type adminCreateUserConfigType struct { - AllowAdminCreateUserOnly types.Bool `tfsdk:"allow_admin_create_user_only"` - InviteMessageTemplate fwtypes.ListNestedObjectValueOf[inviteMessageTemplateType] `tfsdk:"invite_message_template"` - UnusedAccountValidityDays types.Int64 `tfsdk:"unused_account_validity_days"` +type adminCreateUserConfigTypeModel struct { + AllowAdminCreateUserOnly types.Bool `tfsdk:"allow_admin_create_user_only"` + InviteMessageTemplate fwtypes.ListNestedObjectValueOf[messageTemplateTypeModel] `tfsdk:"invite_message_template"` + UnusedAccountValidityDays types.Int64 `tfsdk:"unused_account_validity_days"` } -type inviteMessageTemplateType struct { +type messageTemplateTypeModel struct { EmailMessage types.String `tfsdk:"email_message"` EmailSubject types.String `tfsdk:"email_subject"` - SmsMessage types.String `tfsdk:"sms_message"` + SMSMessage types.String `tfsdk:"sms_message"` } -type deviceConfigurationType struct { +type deviceConfigurationTypeModel struct { ChallengeRequiredOnNewDevice types.Bool `tfsdk:"challenge_required_on_new_device"` DeviceOnlyRememberedOnUserPrompt types.Bool `tfsdk:"device_only_remembered_on_user_prompt"` } -type emailConfigurationType struct { +type emailConfigurationTypeModel struct { ConfigurationSet types.String `tfsdk:"configuration_set"` EmailSendingAccount types.String `tfsdk:"email_sending_account"` From types.String `tfsdk:"from"` ReplyToEmailAddress types.String `tfsdk:"reply_to_email_address"` - SourceArn types.String `tfsdk:"source_arn"` + SourceARN types.String `tfsdk:"source_arn"` } -type lambdaConfigType struct { - CreateAuthChallenge types.String `tfsdk:"create_auth_challenge"` - CustomEmailSender fwtypes.ListNestedObjectValueOf[customEmailSenderType] `tfsdk:"custom_email_sender"` - CustomMessage types.String `tfsdk:"custom_message"` - CustomSMSSender fwtypes.ListNestedObjectValueOf[customSMSSenderType] `tfsdk:"custom_sms_sender"` - DefineAuthChallenge types.String `tfsdk:"define_auth_challenge"` - KmsKeyId types.String `tfsdk:"kms_key_id"` - PostAuthentication types.String `tfsdk:"post_authentication"` - PostConfirmation types.String `tfsdk:"post_confirmation"` - PreAuthentication types.String `tfsdk:"pre_authentication"` - PreSignUp types.String `tfsdk:"pre_sign_up"` - PreTokenGeneration types.String `tfsdk:"pre_token_generation"` - PreTokenGenerationConfig fwtypes.ListNestedObjectValueOf[preTokenGenerationConfigType] `tfsdk:"pre_token_generation_config"` - UserMigration types.String `tfsdk:"user_migration"` - VerifyAuthChallengeResponse types.String `tfsdk:"verify_auth_challenge_response"` +type lambdaConfigTypeModel struct { + CreateAuthChallenge types.String `tfsdk:"create_auth_challenge"` + CustomEmailSender fwtypes.ListNestedObjectValueOf[customEmailLambdaVersionConfigTypeModel] `tfsdk:"custom_email_sender"` + CustomMessage types.String `tfsdk:"custom_message"` + CustomSMSSender fwtypes.ListNestedObjectValueOf[customSMSLambdaVersionConfigTypeModel] `tfsdk:"custom_sms_sender"` + DefineAuthChallenge types.String `tfsdk:"define_auth_challenge"` + KMSKeyID types.String `tfsdk:"kms_key_id"` + PostAuthentication types.String `tfsdk:"post_authentication"` + PostConfirmation types.String `tfsdk:"post_confirmation"` + PreAuthentication types.String `tfsdk:"pre_authentication"` + PreSignUp types.String `tfsdk:"pre_sign_up"` + PreTokenGeneration types.String `tfsdk:"pre_token_generation"` + PreTokenGenerationConfig fwtypes.ListNestedObjectValueOf[preTokenGenerationVersionConfigTypeModel] `tfsdk:"pre_token_generation_config"` + UserMigration types.String `tfsdk:"user_migration"` + VerifyAuthChallengeResponse types.String `tfsdk:"verify_auth_challenge_response"` } -type customEmailSenderType struct { - LambdaArn types.String `tfsdk:"lambda_arn"` +type customEmailLambdaVersionConfigTypeModel struct { + LambdaARN types.String `tfsdk:"lambda_arn"` LambdaVersion types.String `tfsdk:"lambda_version"` } -type customSMSSenderType struct { - LambdaArn types.String `tfsdk:"lambda_arn"` +type customSMSLambdaVersionConfigTypeModel struct { + LambdaARN types.String `tfsdk:"lambda_arn"` LambdaVersion types.String `tfsdk:"lambda_version"` } -type preTokenGenerationConfigType struct { - LambdaArn types.String `tfsdk:"lambda_arn"` +type preTokenGenerationVersionConfigTypeModel struct { + LambdaARN types.String `tfsdk:"lambda_arn"` LambdaVersion types.String `tfsdk:"lambda_version"` } -type recoveryMechanismType struct { - Name types.String `tfsdk:"name"` - Priority types.Int64 `tfsdk:"priority"` -} - -type schemaAttributeType struct { - AttributeDataType types.String `tfsdk:"attribute_data_type"` - DeveloperOnlyAttribute types.Bool `tfsdk:"developer_only_attribute"` - Mutable types.Bool `tfsdk:"mutable"` - Name types.String `tfsdk:"name"` - NumberAttributeConstraints fwtypes.ListNestedObjectValueOf[numberAttributeConstraintsType] `tfsdk:"number_attribute_constraints"` - Required types.Bool `tfsdk:"required"` - StringAttributeConstraints fwtypes.ListNestedObjectValueOf[stringAttributeConstraintsType] `tfsdk:"string_attribute_constraints"` +type schemaAttributeTypeModel struct { + AttributeDataType types.String `tfsdk:"attribute_data_type"` + DeveloperOnlyAttribute types.Bool `tfsdk:"developer_only_attribute"` + Mutable types.Bool `tfsdk:"mutable"` + Name types.String `tfsdk:"name"` + NumberAttributeConstraints fwtypes.ListNestedObjectValueOf[numberAttributeConstraintsTypeModel] `tfsdk:"number_attribute_constraints"` + Required types.Bool `tfsdk:"required"` + StringAttributeConstraints fwtypes.ListNestedObjectValueOf[stringAttributeConstraintsTypeModel] `tfsdk:"string_attribute_constraints"` } -type numberAttributeConstraintsType struct { +type numberAttributeConstraintsTypeModel struct { MaxValue types.String `tfsdk:"max_value"` MinValue types.String `tfsdk:"min_value"` } -type stringAttributeConstraintsType struct { +type stringAttributeConstraintsTypeModel struct { MaxLength types.String `tfsdk:"max_length"` MinLength types.String `tfsdk:"min_length"` } From 173f06dcd8d3ba143234a77a97ff795ab2887c2a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 28 Jun 2024 15:41:00 -0400 Subject: [PATCH 15/15] Run 'make fix-constants PKG=cognitoidp'. --- internal/service/cognitoidp/user_pool_data_source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/cognitoidp/user_pool_data_source.go b/internal/service/cognitoidp/user_pool_data_source.go index 7c0e7dd70d5..3569832adfb 100644 --- a/internal/service/cognitoidp/user_pool_data_source.go +++ b/internal/service/cognitoidp/user_pool_data_source.go @@ -120,7 +120,7 @@ func (d *userPoolDataSource) Schema(ctx context.Context, request datasource.Sche "sms_verification_message": schema.StringAttribute{ Computed: true, }, - "user_pool_id": schema.StringAttribute{ + names.AttrUserPoolID: schema.StringAttribute{ Required: true, }, "user_pool_tags": tftags.TagsAttributeComputedOnly(),