From 9116bd63058059343d9d30354ad05edcb6846453 Mon Sep 17 00:00:00 2001 From: Jonas Verhoelen Date: Tue, 17 Mar 2020 17:14:19 +0100 Subject: [PATCH] resource/aws_cognito_user_pool: Add email_configuration configuration block from_email_address argument (#11607) Output from acceptance testing: ``` --- PASS: TestAccAWSCognitoUserPool_basic (15.19s) --- PASS: TestAccAWSCognitoUserPool_MfaConfiguration_SmsConfiguration (57.33s) --- PASS: TestAccAWSCognitoUserPool_MfaConfiguration_SmsConfigurationAndSoftwareTokenMfaConfiguration (47.43s) --- PASS: TestAccAWSCognitoUserPool_MfaConfiguration_SmsConfigurationToSoftwareTokenMfaConfiguration (30.47s) --- PASS: TestAccAWSCognitoUserPool_MfaConfiguration_SoftwareTokenMfaConfiguration (28.24s) --- PASS: TestAccAWSCognitoUserPool_MfaConfiguration_SoftwareTokenMfaConfigurationToSmsConfiguration (40.94s) --- PASS: TestAccAWSCognitoUserPool_SmsAuthenticationMessage (21.42s) --- PASS: TestAccAWSCognitoUserPool_SmsConfiguration (51.45s) --- PASS: TestAccAWSCognitoUserPool_SmsConfiguration_ExternalId (56.24s) --- PASS: TestAccAWSCognitoUserPool_SmsConfiguration_SnsCallerArn (51.32s) --- PASS: TestAccAWSCognitoUserPool_SmsVerificationMessage (22.61s) --- PASS: TestAccAWSCognitoUserPool_update (43.47s) --- PASS: TestAccAWSCognitoUserPool_withAdminCreateUserConfiguration (25.65s) --- PASS: TestAccAWSCognitoUserPool_withAdminCreateUserConfigurationAndPasswordPolicy (14.56s) --- PASS: TestAccAWSCognitoUserPool_withAdvancedSecurityMode (27.01s) --- PASS: TestAccAWSCognitoUserPool_withAliasAttributes (28.80s) --- PASS: TestAccAWSCognitoUserPool_withDeviceConfiguration (23.96s) --- PASS: TestAccAWSCognitoUserPool_withEmailVerificationMessage (20.43s) --- PASS: TestAccAWSCognitoUserPool_withLambdaConfig (44.34s) --- PASS: TestAccAWSCognitoUserPool_withPasswordPolicy (17.84s) --- PASS: TestAccAWSCognitoUserPool_withSchemaAttributes (17.15s) --- PASS: TestAccAWSCognitoUserPool_withTags (29.88s) --- PASS: TestAccAWSCognitoUserPool_withVerificationMessageTemplate (24.30s) ``` --- aws/resource_aws_cognito_user_pool.go | 12 ++++++++++++ aws/resource_aws_cognito_user_pool_test.go | 13 ++++++++----- aws/structure.go | 4 ++++ website/docs/r/cognito_user_pool.markdown | 1 + 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/aws/resource_aws_cognito_user_pool.go b/aws/resource_aws_cognito_user_pool.go index f991aab2283..3e3faf23d97 100644 --- a/aws/resource_aws_cognito_user_pool.go +++ b/aws/resource_aws_cognito_user_pool.go @@ -151,6 +151,10 @@ func resourceAwsCognitoUserPool() *schema.Resource { Optional: true, ValidateFunc: validateArn, }, + "from_email_address": { + Type: schema.TypeString, + Optional: true, + }, "email_sending_account": { Type: schema.TypeString, Optional: true, @@ -569,6 +573,10 @@ func resourceAwsCognitoUserPoolCreate(d *schema.ResourceData, meta interface{}) 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)) } @@ -999,6 +1007,10 @@ func resourceAwsCognitoUserPoolUpdate(d *schema.ResourceData, meta interface{}) emailConfigurationType.EmailSendingAccount = aws.String(v.(string)) } + if v, ok := config["from_email_address"]; ok && v.(string) != "" { + emailConfigurationType.From = aws.String(v.(string)) + } + params.EmailConfiguration = emailConfigurationType } } diff --git a/aws/resource_aws_cognito_user_pool_test.go b/aws/resource_aws_cognito_user_pool_test.go index 39221f3aeff..4c468ba4681 100644 --- a/aws/resource_aws_cognito_user_pool_test.go +++ b/aws/resource_aws_cognito_user_pool_test.go @@ -704,11 +704,12 @@ func TestAccAWSCognitoUserPool_withEmailConfiguration(t *testing.T) { CheckDestroy: testAccCheckAWSCognitoUserPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCognitoUserPoolConfig_withEmailConfiguration(name, "", "", "COGNITO_DEFAULT"), + Config: testAccAWSCognitoUserPoolConfig_withEmailConfiguration(name, "", "", "", "COGNITO_DEFAULT"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "email_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "email_configuration.0.reply_to_email_address", ""), resource.TestCheckResourceAttr(resourceName, "email_configuration.0.email_sending_account", "COGNITO_DEFAULT"), + resource.TestCheckResourceAttr(resourceName, "email_configuration.0.from_email_address", ""), ), }, { @@ -717,12 +718,13 @@ func TestAccAWSCognitoUserPool_withEmailConfiguration(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCognitoUserPoolConfig_withEmailConfiguration(name, replyTo, sourceARN, "DEVELOPER"), + Config: testAccAWSCognitoUserPoolConfig_withEmailConfiguration(name, replyTo, sourceARN, "John Smith ", "DEVELOPER"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "email_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "email_configuration.0.reply_to_email_address", replyTo), resource.TestCheckResourceAttr(resourceName, "email_configuration.0.email_sending_account", "DEVELOPER"), resource.TestCheckResourceAttr(resourceName, "email_configuration.0.source_arn", sourceARN), + resource.TestCheckResourceAttr(resourceName, "email_configuration.0.from_email_address", "John Smith "), ), }, }, @@ -1473,7 +1475,7 @@ resource "aws_cognito_user_pool" "test" { `, name, tagKey1, tagValue1, tagKey2, tagValue2) } -func testAccAWSCognitoUserPoolConfig_withEmailConfiguration(name, email, arn, account string) string { +func testAccAWSCognitoUserPoolConfig_withEmailConfiguration(name, email, arn, from, account string) string { return fmt.Sprintf(` resource "aws_cognito_user_pool" "test" { name = "terraform-test-pool-%[1]s" @@ -1482,9 +1484,10 @@ resource "aws_cognito_user_pool" "test" { email_configuration { reply_to_email_address = %[2]q source_arn = %[3]q - email_sending_account = %[4]q + from_email_address = %[4]q + email_sending_account = %[5]q } - }`, name, email, arn, account) + }`, name, email, arn, from, account) } func testAccAWSCognitoUserPoolConfig_withAliasAttributes(name string) string { diff --git a/aws/structure.go b/aws/structure.go index a7f806a3de5..513382cface 100644 --- a/aws/structure.go +++ b/aws/structure.go @@ -2530,6 +2530,10 @@ func flattenCognitoUserPoolEmailConfiguration(s *cognitoidentityprovider.EmailCo m["reply_to_email_address"] = *s.ReplyToEmailAddress } + if s.From != nil { + m["from_email_address"] = *s.From + } + if s.SourceArn != nil { m["source_arn"] = *s.SourceArn } diff --git a/website/docs/r/cognito_user_pool.markdown b/website/docs/r/cognito_user_pool.markdown index 1de43bb508e..524ba824030 100644 --- a/website/docs/r/cognito_user_pool.markdown +++ b/website/docs/r/cognito_user_pool.markdown @@ -89,6 +89,7 @@ The following arguments are supported: * `reply_to_email_address` (Optional) - The REPLY-TO email address. * `source_arn` (Optional) - The ARN of the email source. + * `from_email_address` (Optional) - Sender’s email address or sender’s name with their email address (e.g. "john@smith.com" or "John Smith ") * `email_sending_account` (Optional) - Instruct Cognito to either use its built-in functional or Amazon SES to send out emails. #### Lambda Configuration