Skip to content

Commit

Permalink
Merge pull request #19704 from DrFaust92/r/cognito_user_pool_supress_…
Browse files Browse the repository at this point in the history
…diff

r/cognito_user_pool: Suppress diff for empty `account_recovery_setting`
  • Loading branch information
anGie44 committed Jun 10, 2021
2 parents cdbe83b + 6681af6 commit 1ac5e4d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .changelog/19704.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_cognito_user_pool: Suppress diff for empty `account_recovery_setting`.
```
102 changes: 37 additions & 65 deletions aws/resource_aws_cognito_user_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ func resourceAwsCognitoUserPool() *schema.Resource {
// https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html
Schema: map[string]*schema.Schema{
"account_recovery_setting": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: suppressMissingOptionalConfigurationBlock,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"recovery_mechanism": {
Expand Down Expand Up @@ -612,35 +613,8 @@ func resourceAwsCognitoUserPoolCreate(d *schema.ResourceData, meta interface{})
params.AutoVerifiedAttributes = expandStringSet(v.(*schema.Set))
}

if v, ok := d.GetOk("email_configuration"); ok {
configs := v.([]interface{})
config, ok := configs[0].(map[string]interface{})

if ok && config != nil {
emailConfigurationType := &cognitoidentityprovider.EmailConfigurationType{}

if v, ok := config["reply_to_email_address"]; ok && v.(string) != "" {
emailConfigurationType.ReplyToEmailAddress = aws.String(v.(string))
}

if v, ok := config["source_arn"]; ok && v.(string) != "" {
emailConfigurationType.SourceArn = aws.String(v.(string))
}

if v, ok := config["from_email_address"]; ok && v.(string) != "" {
emailConfigurationType.From = aws.String(v.(string))
}

if v, ok := config["email_sending_account"]; ok && v.(string) != "" {
emailConfigurationType.EmailSendingAccount = aws.String(v.(string))
}

if v, ok := config["configuration_set"]; ok && v.(string) != "" {
emailConfigurationType.ConfigurationSet = aws.String(v.(string))
}

params.EmailConfiguration = emailConfigurationType
}
if v, ok := d.GetOk("email_configuration"); ok && len(v.([]interface{})) > 0 {
params.EmailConfiguration = expandCognitoUserPoolEmailConfig(v.([]interface{}))
}

if v, ok := d.GetOk("admin_create_user_config"); ok {
Expand Down Expand Up @@ -690,8 +664,7 @@ func resourceAwsCognitoUserPoolCreate(d *schema.ResourceData, meta interface{})
}

if v, ok := d.GetOk("schema"); ok {
configs := v.(*schema.Set).List()
params.Schema = expandCognitoUserPoolSchema(configs)
params.Schema = expandCognitoUserPoolSchema(v.(*schema.Set).List())
}

// For backwards compatibility, include this outside of MFA configuration
Expand Down Expand Up @@ -1084,37 +1057,8 @@ func resourceAwsCognitoUserPoolUpdate(d *schema.ResourceData, meta interface{})
}
}

if v, ok := d.GetOk("email_configuration"); ok {

configs := v.([]interface{})
config, ok := configs[0].(map[string]interface{})

if ok && config != nil {
log.Printf("[DEBUG] Set Values to update from configs")
emailConfigurationType := &cognitoidentityprovider.EmailConfigurationType{}

if v, ok := config["reply_to_email_address"]; ok && v.(string) != "" {
emailConfigurationType.ReplyToEmailAddress = aws.String(v.(string))
}

if v, ok := config["source_arn"]; ok && v.(string) != "" {
emailConfigurationType.SourceArn = aws.String(v.(string))
}

if v, ok := config["email_sending_account"]; ok && v.(string) != "" {
emailConfigurationType.EmailSendingAccount = aws.String(v.(string))
}

if v, ok := config["from_email_address"]; ok && v.(string) != "" {
emailConfigurationType.From = aws.String(v.(string))
}

if v, ok := config["configuration_set"]; ok && v.(string) != "" {
emailConfigurationType.ConfigurationSet = aws.String(v.(string))
}

params.EmailConfiguration = emailConfigurationType
}
if v, ok := d.GetOk("email_configuration"); ok && len(v.([]interface{})) > 0 {
params.EmailConfiguration = expandCognitoUserPoolEmailConfig(v.([]interface{}))
}

if v, ok := d.GetOk("email_verification_subject"); ok {
Expand Down Expand Up @@ -2248,3 +2192,31 @@ func flattenCognitoUserPoolCustomEmailSender(u *cognitoidentityprovider.CustomEm

return []map[string]interface{}{m}
}

func expandCognitoUserPoolEmailConfig(emailConfig []interface{}) *cognitoidentityprovider.EmailConfigurationType {
config := emailConfig[0].(map[string]interface{})

emailConfigurationType := &cognitoidentityprovider.EmailConfigurationType{}

if v, ok := config["reply_to_email_address"]; ok && v.(string) != "" {
emailConfigurationType.ReplyToEmailAddress = aws.String(v.(string))
}

if v, ok := config["source_arn"]; ok && v.(string) != "" {
emailConfigurationType.SourceArn = aws.String(v.(string))
}

if v, ok := config["from_email_address"]; ok && v.(string) != "" {
emailConfigurationType.From = aws.String(v.(string))
}

if v, ok := config["email_sending_account"]; ok && v.(string) != "" {
emailConfigurationType.EmailSendingAccount = aws.String(v.(string))
}

if v, ok := config["configuration_set"]; ok && v.(string) != "" {
emailConfigurationType.ConfigurationSet = aws.String(v.(string))
}

return emailConfigurationType
}

0 comments on commit 1ac5e4d

Please sign in to comment.