vishal
vishal

Reputation: 1874

Terraform Error while creating AWS Cognito Userpool

Below is my terraform code to create a Cognito Userpool.

resource "aws_cognito_user_pool" "sample_application" {
    name = "sampletest-pool"
    schema {
            name                    = "email"
            attribute_data_type     = "String"
            required                = true
            string_attribute_constraints {
            }
    }
    schema {
            name                    = "name"
            attribute_data_type     = "String"
            required                = true
            string_attribute_constraints {
                min_length = 1
                max_length = 50
            }
    }
    schema {
            name                    = "family_name"
            attribute_data_type     = "String"
            required                = true
            string_attribute_constraints {
                min_length = 1
                max_length = 50
            }
    }
    schema {
            name                     = "phone_number"
            developer_only_attribute = true
            attribute_data_type      = "Number"
            required                 = true
            number_attribute_constraints {}
    }
}

When I give terraform apply I'm displayed with the below error.

╷ │ Error: error creating Cognito User Pool: InvalidParameterException: You can not change AttributeDataType or set developerOnlyAttribute for standard schema attribute phone_number │ │ with aws_cognito_user_pool.sample_application, │ on cognito.tf line 1, in resource "aws_cognito_user_pool" "sample_application": │ 1: resource "aws_cognito_user_pool" "sample_application" { │ ╵

I know I'm making a small mistake but unable to find it and the official docs don't have any example for this usecase at all. Official Docs: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool

Upvotes: 0

Views: 1578

Answers (1)

bembas
bembas

Reputation: 771

As the error says you cannot set developerOnlyAttribute for standard schema attributes (Standard Atrtibutes )

Also phone number attribute_data_type should be string and cannot be changed.

 schema {
            name                     = "phone_number"
            attribute_data_type      = "String"
            required                 = true
    }

Upvotes: 2

Related Questions