创建 AWS Cognito 用户池时出现 Terraform 错误
Terraform Error while creating AWS Cognito Userpool
下面是我创建 Cognito 用户池的 terraform 代码。
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 {}
}
}
当我给出 terraform apply
时,我会显示以下错误。
╷ │ 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" { │ ╵
我知道我犯了一个小错误但无法找到它并且官方文档根本没有这个用例的任何示例。
官方文档: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool
如错误所述,您无法为标准架构属性设置 developerOnlyAttribute (Standard Atrtibutes)
此外 phone 数字 attribute_data_type 应该是字符串并且不能更改。
schema {
name = "phone_number"
attribute_data_type = "String"
required = true
}
下面是我创建 Cognito 用户池的 terraform 代码。
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 {}
}
}
当我给出 terraform apply
时,我会显示以下错误。
╷ │ 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" { │ ╵
我知道我犯了一个小错误但无法找到它并且官方文档根本没有这个用例的任何示例。 官方文档: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool
如错误所述,您无法为标准架构属性设置 developerOnlyAttribute (Standard Atrtibutes)
此外 phone 数字 attribute_data_type 应该是字符串并且不能更改。
schema {
name = "phone_number"
attribute_data_type = "String"
required = true
}