From e7e4474e8a280671cf0aff357e0de57c85dfcbbe Mon Sep 17 00:00:00 2001 From: nywilken Date: Fri, 2 Aug 2019 16:41:26 -0400 Subject: [PATCH 1/2] resource/aws_cognito_user_pool: Fix perpetual diffs on sms_verification_message When using `verification_message_template.sms_message` for setting the sms message verification template the resource upon subsequent applys will trigger an update because of a diff in the conflicting `sms_verification_message` argument. This changes adds the computed property onto `sms_message_verification` to ensure it get's updated with the contents being set by `verification_message_template.sms_message` Acceptance test before change ``` --- FAIL: TestAccAWSCognitoUserPool_withVerificationMessageTemplate (10.90s) [274/322] testing.go:568: Step 0 error: After applying this step, the plan was not empty: DIFF: UPDATE: aws_cognito_user_pool.pool sms_verification_message: "{####} Baz" => "" ``` Acceptance test after change ``` --- PASS: TestAccAWSCognitoUserPool_withVerificationMessageTemp ``` --- aws/resource_aws_cognito_user_pool.go | 1 + aws/resource_aws_cognito_user_pool_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_cognito_user_pool.go b/aws/resource_aws_cognito_user_pool.go index 6b8dfbcd12a..b1eb81c2cd7 100644 --- a/aws/resource_aws_cognito_user_pool.go +++ b/aws/resource_aws_cognito_user_pool.go @@ -410,6 +410,7 @@ func resourceAwsCognitoUserPool() *schema.Resource { "sms_verification_message": { Type: schema.TypeString, Optional: true, + Computed: true, ValidateFunc: validateCognitoUserPoolSmsVerificationMessage, ConflictsWith: []string{"verification_message_template.0.sms_message"}, }, diff --git a/aws/resource_aws_cognito_user_pool_test.go b/aws/resource_aws_cognito_user_pool_test.go index e3861f3d621..16ca3652441 100644 --- a/aws/resource_aws_cognito_user_pool_test.go +++ b/aws/resource_aws_cognito_user_pool_test.go @@ -1200,7 +1200,6 @@ resource "aws_cognito_user_pool" "pool" { email_verification_message = "Foo {####} Bar" email_verification_subject = "FooBar {####}" - sms_verification_message = "{####} Baz" # Setting Verification template attributes like EmailMessage, EmailSubject or SmsMessage # will implicitly set EmailVerificationMessage, EmailVerificationSubject and SmsVerificationMessage @@ -1209,6 +1208,7 @@ resource "aws_cognito_user_pool" "pool" { default_email_option = "CONFIRM_WITH_LINK" email_message_by_link = "{##foobar##}" email_subject_by_link = "foobar" + sms_message = "{####} Baz" } } `, name) From b0c5ef46bb89e2c47e3e91032fb4e3c660722de6 Mon Sep 17 00:00:00 2001 From: nywilken Date: Wed, 4 Sep 2019 15:30:32 -0400 Subject: [PATCH 2/2] Update test to verify bidirectional property changes --- aws/resource_aws_cognito_user_pool_test.go | 40 +++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/aws/resource_aws_cognito_user_pool_test.go b/aws/resource_aws_cognito_user_pool_test.go index 16ca3652441..591c3ae0c71 100644 --- a/aws/resource_aws_cognito_user_pool_test.go +++ b/aws/resource_aws_cognito_user_pool_test.go @@ -577,17 +577,34 @@ func TestAccAWSCognitoUserPool_withVerificationMessageTemplate(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckAWSCognitoUserPoolExists("aws_cognito_user_pool.pool"), resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.default_email_option", "CONFIRM_WITH_LINK"), - resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.email_message", "Foo {####} Bar"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.email_message", "foo {####} bar"), resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.email_message_by_link", "{##foobar##}"), - resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.email_subject", "FooBar {####}"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.email_subject", "foobar {####}"), resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.email_subject_by_link", "foobar"), - resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.sms_message", "{####} Baz"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.sms_message", "{####} baz"), + + /* Setting Verification template attributes like EmailMessage, EmailSubject or SmsMessage + will implicitly set EmailVerificationMessage, EmailVerificationSubject and SmsVerificationMessage attributes. + */ + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "email_verification_message", "foo {####} bar"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "email_verification_subject", "foobar {####}"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "sms_verification_message", "{####} baz"), ), }, { - Config: testAccAWSCognitoUserPoolConfig_withVerificationMessageTemplateUpdated(name), + Config: testAccAWSCognitoUserPoolConfig_withVerificationMessageTemplate_DefaultEmailOption(name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.default_email_option", "CONFIRM_WITH_CODE"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "email_verification_message", "{####} Baz"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "email_verification_subject", "BazBaz {####}"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "sms_verification_message", "{####} BazBazBar?"), + + /* Setting EmailVerificationMessage, EmailVerificationSubject and SmsVerificationMessage attributes + will implicitly set verification template attributes like EmailMessage, EmailSubject or SmsMessage. + */ + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.email_message", "{####} Baz"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.email_subject", "BazBaz {####}"), + resource.TestCheckResourceAttr("aws_cognito_user_pool.pool", "verification_message_template.0.sms_message", "{####} BazBazBar?"), ), }, }, @@ -1198,30 +1215,29 @@ func testAccAWSCognitoUserPoolConfig_withVerificationMessageTemplate(name string resource "aws_cognito_user_pool" "pool" { name = "terraform-test-pool-%s" - email_verification_message = "Foo {####} Bar" - email_verification_subject = "FooBar {####}" - # Setting Verification template attributes like EmailMessage, EmailSubject or SmsMessage # will implicitly set EmailVerificationMessage, EmailVerificationSubject and SmsVerificationMessage # attributes. verification_message_template { default_email_option = "CONFIRM_WITH_LINK" + email_message = "foo {####} bar" email_message_by_link = "{##foobar##}" + email_subject = "foobar {####}" email_subject_by_link = "foobar" - sms_message = "{####} Baz" + sms_message = "{####} baz" } } `, name) } -func testAccAWSCognitoUserPoolConfig_withVerificationMessageTemplateUpdated(name string) string { +func testAccAWSCognitoUserPoolConfig_withVerificationMessageTemplate_DefaultEmailOption(name string) string { return fmt.Sprintf(` resource "aws_cognito_user_pool" "pool" { name = "terraform-test-pool-%s" - email_verification_message = "Foo {####} Bar" - email_verification_subject = "FooBar {####}" - sms_verification_message = "{####} Baz" + email_verification_message = "{####} Baz" + email_verification_subject = "BazBaz {####}" + sms_verification_message = "{####} BazBazBar?" verification_message_template { default_email_option = "CONFIRM_WITH_CODE"