Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure "FROM email address" for Cognito user pool (aws_cognito_user_pool) #11607

Merged
merged 3 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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