Skip to content

Commit

Permalink
resource/aws_cognito_user_pool: Add email_configuration configuration…
Browse files Browse the repository at this point in the history
… 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)
```
  • Loading branch information
jonas-pietzsch authored Mar 17, 2020
1 parent c563fb8 commit 9116bd6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
12 changes: 12 additions & 0 deletions aws/resource_aws_cognito_user_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
}
}
Expand Down
13 changes: 8 additions & 5 deletions aws/resource_aws_cognito_user_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""),
),
},
{
Expand All @@ -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 <john@smith.com>", "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 <john@smith.com>"),
),
},
},
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/cognito_user_pool.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 <john@smith.com>")
* `email_sending_account` (Optional) - Instruct Cognito to either use its built-in functional or Amazon SES to send out emails.

#### Lambda Configuration
Expand Down

0 comments on commit 9116bd6

Please sign in to comment.