Skip to content

Commit

Permalink
Merge pull request #3789 from terraform-providers/b-aws_cognito_user_…
Browse files Browse the repository at this point in the history
…pool-set-schema

resource/aws_cognito_user_pool: Fix schema attribute handling
  • Loading branch information
bflad authored Mar 26, 2018
2 parents cedd007 + 41e3d05 commit 6fed0a5
Show file tree
Hide file tree
Showing 4 changed files with 418 additions and 29 deletions.
19 changes: 19 additions & 0 deletions aws/resource_aws_cognito_user_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func resourceAwsCognitoUserPool() *schema.Resource {
"attribute_data_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
cognitoidentityprovider.AttributeDataTypeString,
cognitoidentityprovider.AttributeDataTypeNumber,
Expand All @@ -294,50 +295,60 @@ func resourceAwsCognitoUserPool() *schema.Resource {
"developer_only_attribute": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"mutable": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateCognitoUserPoolSchemaName,
},
"number_attribute_constraints": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"min_value": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"max_value": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
},
},
"required": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"string_attribute_constraints": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"min_length": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"max_length": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
},
Expand Down Expand Up @@ -674,6 +685,14 @@ func resourceAwsCognitoUserPoolRead(d *schema.ResourceData, meta interface{}) er
}
}

var configuredSchema []interface{}
if v, ok := d.GetOk("schema"); ok {
configuredSchema = v.(*schema.Set).List()
}
if err := d.Set("schema", flattenCognitoUserPoolSchema(expandCognitoUserPoolSchema(configuredSchema), resp.UserPool.SchemaAttributes)); err != nil {
return fmt.Errorf("Failed setting schema: %s", err)
}

if err := d.Set("sms_configuration", flattenCognitoUserPoolSmsConfiguration(resp.UserPool.SmsConfiguration)); err != nil {
return fmt.Errorf("Failed setting sms_configuration: %s", err)
}
Expand Down
6 changes: 5 additions & 1 deletion aws/resource_aws_cognito_user_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ func TestAccAWSCognitoUserPool_withSchemaAttributes(t *testing.T) {
{
Config: testAccAWSCognitoUserPoolConfig_withSchemaAttributesUpdated(name),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("aws_cognito_user_pool.main", "schema.#", "2"),
resource.TestCheckResourceAttr("aws_cognito_user_pool.main", "schema.#", "2"),
resource.TestCheckResourceAttr("aws_cognito_user_pool.main", "schema.2078884933.attribute_data_type", "String"),
resource.TestCheckResourceAttr("aws_cognito_user_pool.main", "schema.2078884933.developer_only_attribute", "false"),
Expand All @@ -425,6 +424,11 @@ func TestAccAWSCognitoUserPool_withSchemaAttributes(t *testing.T) {
resource.TestCheckResourceAttr("aws_cognito_user_pool.main", "schema.2718111653.string_attribute_constraints.#", "0"),
),
},
{
ResourceName: "aws_cognito_user_pool.main",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
Loading

0 comments on commit 6fed0a5

Please sign in to comment.