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

Add configuration set support for Cognito user pools #16749

Closed
wants to merge 2 commits into from
Closed
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 @@ -155,6 +155,10 @@ func resourceAwsCognitoUserPool() *schema.Resource {
cognitoidentityprovider.EmailSendingAccountTypeDeveloper,
}, false),
},
"configuration_set": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -622,6 +626,10 @@ func resourceAwsCognitoUserPoolCreate(d *schema.ResourceData, meta interface{})
emailConfigurationType.EmailSendingAccount = aws.String(v.(string))
}

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

params.EmailConfiguration = emailConfigurationType
}
}
Expand Down Expand Up @@ -1076,6 +1084,10 @@ func resourceAwsCognitoUserPoolUpdate(d *schema.ResourceData, meta interface{})
emailConfigurationType.From = aws.String(v.(string))
}

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

params.EmailConfiguration = emailConfigurationType
}
}
Expand Down
16 changes: 12 additions & 4 deletions aws/resource_aws_cognito_user_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,18 +728,24 @@ func TestAccAWSCognitoUserPool_withEmailConfiguration(t *testing.T) {
t.Skip("'TEST_AWS_SES_VERIFIED_EMAIL_ARN' not set, skipping test.")
}

configurationSet, ok := os.LookupEnv("TEST_AWS_SES_CONFIGURATION_SET")
if !ok {
t.Skip("'TEST_AWS_SES_CONFIGURATION_SET' not set, skipping test.")
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCognitoIdentityProvider(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCognitoUserPoolDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCognitoUserPoolConfig_withEmailConfiguration(rName, "", "", "", "COGNITO_DEFAULT"),
Config: testAccAWSCognitoUserPoolConfig_withEmailConfiguration(rName, "", "", "", "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", ""),
resource.TestCheckResourceAttr(resourceName, "email_configuration.0.configuration_set", ""),
),
},
{
Expand All @@ -748,13 +754,14 @@ func TestAccAWSCognitoUserPool_withEmailConfiguration(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccAWSCognitoUserPoolConfig_withEmailConfiguration(rName, replyTo, sourceARN, "John Smith <john@smith.com>", "DEVELOPER"),
Config: testAccAWSCognitoUserPoolConfig_withEmailConfiguration(rName, replyTo, sourceARN, "John Smith <john@smith.com>", "DEVELOPER", configurationSet),
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>"),
resource.TestCheckResourceAttr(resourceName, "email_configuration.0.configuration_set", configurationSet),
),
},
},
Expand Down Expand Up @@ -1594,7 +1601,7 @@ resource "aws_cognito_user_pool" "test" {
`, rName, tagKey1, tagValue1, tagKey2, tagValue2)
}

func testAccAWSCognitoUserPoolConfig_withEmailConfiguration(rName, email, arn, from, account string) string {
func testAccAWSCognitoUserPoolConfig_withEmailConfiguration(rName, email, arn, from, account, configuration_set string) string {
return fmt.Sprintf(`
resource "aws_cognito_user_pool" "test" {
name = %[1]q
Expand All @@ -1604,9 +1611,10 @@ resource "aws_cognito_user_pool" "test" {
source_arn = %[3]q
from_email_address = %[4]q
email_sending_account = %[5]q
configuration_set = %[6]q
}
}
`, rName, email, arn, from, account)
`, rName, email, arn, from, account, configuration_set)
}

func testAccAWSCognitoUserPoolConfig_withAliasAttributes(rName 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 @@ -2406,6 +2406,10 @@ func flattenCognitoUserPoolEmailConfiguration(s *cognitoidentityprovider.EmailCo
m["email_sending_account"] = *s.EmailSendingAccount
}

if s.ConfigurationSet != nil {
m["configuration_set"] = *s.ConfigurationSet
}

if len(m) > 0 {
return []map[string]interface{}{m}
}
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 @@ -112,6 +112,7 @@ The following arguments are supported:
* `source_arn` (Optional) - The ARN of the SES verified email identity to to use. Required if `email_sending_account` is set to `DEVELOPER`.
* `from_email_address` (Optional) - Sender’s email address or sender’s display name with their email address (e.g. `john@example.com`, `John Smith <john@example.com>` or `\"John Smith Ph.D.\" <john@example.com>`). Escaped double quotes are required around display names that contain certain characters as specified in [RFC 5322](https://tools.ietf.org/html/rfc5322).
* `email_sending_account` (Optional) - The email delivery method to use. `COGNITO_DEFAULT` for the default email functionality built into Cognito or `DEVELOPER` to use your Amazon SES configuration.
* `configuration_set` (Optional) - The email configuration set name from SES.

#### Lambda Configuration

Expand Down