Skip to content

Commit

Permalink
Merge pull request #18512 from hashicorp/f-allow_schema_additions
Browse files Browse the repository at this point in the history
Allow schema additions in cognito user pools
  • Loading branch information
bill-rich authored Apr 1, 2021
2 parents 4f0a139 + 381f4bd commit d6103d8
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .changelog/18512.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_cognito_user_pool: Allow schema items to be added without recreating resource.
```
28 changes: 16 additions & 12 deletions aws/resource_aws_cognito_user_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,74 +306,62 @@ func resourceAwsCognitoUserPool() *schema.Resource {
"schema": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
MinItems: 1,
MaxItems: 50,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"attribute_data_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(cognitoidentityprovider.AttributeDataType_Values(), false),
},
"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 @@ -1154,6 +1142,22 @@ func resourceAwsCognitoUserPoolUpdate(d *schema.ResourceData, meta interface{})
}
}

if d.HasChange("schema") {
oldSchema, newSchema := d.GetChange("schema")
if oldSchema.(*schema.Set).Difference(newSchema.(*schema.Set)).Len() == 0 {
params := &cognitoidentityprovider.AddCustomAttributesInput{
UserPoolId: aws.String(d.Id()),
CustomAttributes: expandCognitoUserPoolSchema(newSchema.(*schema.Set).Difference(oldSchema.(*schema.Set)).List()),
}
_, err := conn.AddCustomAttributes(params)
if err != nil {
return fmt.Errorf("error updating Cognito User Pool (%s): unable to add custom attributes from schema: %w", d.Id(), err)
}
} else {
return fmt.Errorf("error updating Cognito User Pool (%s): cannot modify or remove schema items", d.Id())
}
}

return resourceAwsCognitoUserPoolRead(d, meta)
}

Expand Down
Loading

0 comments on commit d6103d8

Please sign in to comment.