diff --git a/aws/resource_aws_ses_domain_identity_test.go b/aws/resource_aws_ses_domain_identity_test.go index d22ca76065b..4b7abc2677b 100644 --- a/aws/resource_aws_ses_domain_identity_test.go +++ b/aws/resource_aws_ses_domain_identity_test.go @@ -34,6 +34,28 @@ func TestAccAWSSESDomainIdentity_basic(t *testing.T) { }) } +func TestAccAWSSESDomainIdentity_disappears(t *testing.T) { + domain := fmt.Sprintf( + "%s.terraformtesting.com", + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsSESDomainIdentityDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAwsSESDomainIdentityConfig(domain), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsSESDomainIdentityExists("aws_ses_domain_identity.test"), + testAccCheckAwsSESDomainIdentityDisappears(domain), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func TestAccAWSSESDomainIdentity_trailingPeriod(t *testing.T) { domain := fmt.Sprintf( "%s.terraformtesting.com.", @@ -116,6 +138,20 @@ func testAccCheckAwsSESDomainIdentityExists(n string) resource.TestCheckFunc { } } +func testAccCheckAwsSESDomainIdentityDisappears(identity string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).sesConn + + input := &ses.DeleteIdentityInput{ + Identity: aws.String(identity), + } + + _, err := conn.DeleteIdentity(input) + + return err + } +} + func testAccCheckAwsSESDomainIdentityArn(n string, domain string) resource.TestCheckFunc { return func(s *terraform.State) error { rs := s.RootModule().Resources[n] diff --git a/aws/resource_aws_ses_domain_mail_from.go b/aws/resource_aws_ses_domain_mail_from.go index c7361a60760..3174702039c 100644 --- a/aws/resource_aws_ses_domain_mail_from.go +++ b/aws/resource_aws_ses_domain_mail_from.go @@ -73,21 +73,27 @@ func resourceAwsSesDomainMailFromRead(d *schema.ResourceData, meta interface{}) } out, err := conn.GetIdentityMailFromDomainAttributes(readOpts) + if err != nil { - log.Printf("error fetching MAIL FROM domain attributes for %s: %s", domainName, err) - return err + return fmt.Errorf("error fetching SES MAIL FROM domain attributes for %s: %s", domainName, err) } - d.Set("domain", domainName) + if out == nil { + return fmt.Errorf("error fetching SES MAIL FROM domain attributes for %s: empty response", domainName) + } - if v, ok := out.MailFromDomainAttributes[domainName]; ok { - d.Set("behavior_on_mx_failure", v.BehaviorOnMXFailure) - d.Set("mail_from_domain", v.MailFromDomain) - } else { - d.Set("behavior_on_mx_failure", v.BehaviorOnMXFailure) - d.Set("mail_from_domain", "") + attributes, ok := out.MailFromDomainAttributes[domainName] + + if !ok { + log.Printf("[WARN] SES Domain Identity (%s) not found, removing from state", domainName) + d.SetId("") + return nil } + d.Set("behavior_on_mx_failure", attributes.BehaviorOnMXFailure) + d.Set("domain", domainName) + d.Set("mail_from_domain", attributes.MailFromDomain) + return nil } diff --git a/aws/resource_aws_ses_domain_mail_from_test.go b/aws/resource_aws_ses_domain_mail_from_test.go index d421a97b34d..1e72f172353 100644 --- a/aws/resource_aws_ses_domain_mail_from_test.go +++ b/aws/resource_aws_ses_domain_mail_from_test.go @@ -51,6 +51,54 @@ func TestAccAWSSESDomainMailFrom_basic(t *testing.T) { }) } +func TestAccAWSSESDomainMailFrom_disappears(t *testing.T) { + domain := fmt.Sprintf( + "%s.terraformtesting.com", + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + mailFromDomain := fmt.Sprintf("bounce.%s", domain) + resourceName := "aws_ses_domain_mail_from.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckSESDomainMailFromDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAwsSESDomainMailFromConfig(domain, mailFromDomain), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsSESDomainMailFromExists(resourceName), + testAccCheckAwsSESDomainMailFromDisappears(domain), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccAWSSESDomainMailFrom_disappears_Identity(t *testing.T) { + domain := fmt.Sprintf( + "%s.terraformtesting.com", + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + mailFromDomain := fmt.Sprintf("bounce.%s", domain) + resourceName := "aws_ses_domain_mail_from.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckSESDomainMailFromDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAwsSESDomainMailFromConfig(domain, mailFromDomain), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsSESDomainMailFromExists(resourceName), + testAccCheckAwsSESDomainIdentityDisappears(domain), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func TestAccAWSSESDomainMailFrom_behaviorOnMxFailure(t *testing.T) { domain := fmt.Sprintf( "%s.terraformtesting.com", @@ -142,6 +190,21 @@ func testAccCheckSESDomainMailFromDestroy(s *terraform.State) error { return nil } +func testAccCheckAwsSESDomainMailFromDisappears(identity string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).sesConn + + input := &ses.SetIdentityMailFromDomainInput{ + Identity: aws.String(identity), + MailFromDomain: nil, + } + + _, err := conn.SetIdentityMailFromDomain(input) + + return err + } +} + func testAccAwsSESDomainMailFromConfig(domain, mailFromDomain string) string { return fmt.Sprintf(` resource "aws_ses_domain_identity" "test" {