From 32ea4d584c044391af0434e313042946824324e6 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Mon, 7 Jun 2021 23:58:57 +0300 Subject: [PATCH 1/2] extract email config + supress diff --- aws/resource_aws_cognito_user_pool.go | 102 ++++++++++---------------- 1 file changed, 37 insertions(+), 65 deletions(-) diff --git a/aws/resource_aws_cognito_user_pool.go b/aws/resource_aws_cognito_user_pool.go index 61a9bf67471..a347a222c27 100644 --- a/aws/resource_aws_cognito_user_pool.go +++ b/aws/resource_aws_cognito_user_pool.go @@ -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": { @@ -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 { @@ -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 @@ -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 { @@ -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 +} From 6681af63c6abb8c7a153ca0772bc2d5718174aaf Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Tue, 8 Jun 2021 00:01:56 +0300 Subject: [PATCH 2/2] changelog --- .changelog/19704.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/19704.txt diff --git a/.changelog/19704.txt b/.changelog/19704.txt new file mode 100644 index 00000000000..1f47903d762 --- /dev/null +++ b/.changelog/19704.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_cognito_user_pool: Suppress diff for empty `account_recovery_setting`. +``` \ No newline at end of file