github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_ses_domain_identity_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/service/ses" 9 "github.com/hashicorp/terraform/helper/acctest" 10 "github.com/hashicorp/terraform/helper/resource" 11 "github.com/hashicorp/terraform/terraform" 12 ) 13 14 func TestAccAwsSESDomainIdentity_basic(t *testing.T) { 15 resource.Test(t, resource.TestCase{ 16 PreCheck: func() { 17 testAccPreCheck(t) 18 }, 19 Providers: testAccProviders, 20 CheckDestroy: testAccCheckAwsSESDomainIdentityDestroy, 21 Steps: []resource.TestStep{ 22 resource.TestStep{ 23 Config: fmt.Sprintf( 24 testAccAwsSESDomainIdentityConfig, 25 acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum), 26 ), 27 Check: resource.ComposeTestCheckFunc( 28 testAccCheckAwsSESDomainIdentityExists("aws_ses_domain_identity.test"), 29 ), 30 }, 31 }, 32 }) 33 } 34 35 func testAccCheckAwsSESDomainIdentityDestroy(s *terraform.State) error { 36 conn := testAccProvider.Meta().(*AWSClient).sesConn 37 38 for _, rs := range s.RootModule().Resources { 39 if rs.Type != "aws_ses_domain_identity" { 40 continue 41 } 42 43 domain := rs.Primary.ID 44 params := &ses.GetIdentityVerificationAttributesInput{ 45 Identities: []*string{ 46 aws.String(domain), 47 }, 48 } 49 50 response, err := conn.GetIdentityVerificationAttributes(params) 51 if err != nil { 52 return err 53 } 54 55 if response.VerificationAttributes[domain] != nil { 56 return fmt.Errorf("SES Domain Identity %s still exists. Failing!", domain) 57 } 58 } 59 60 return nil 61 } 62 63 func testAccCheckAwsSESDomainIdentityExists(n string) resource.TestCheckFunc { 64 return func(s *terraform.State) error { 65 rs, ok := s.RootModule().Resources[n] 66 if !ok { 67 return fmt.Errorf("SES Domain Identity not found: %s", n) 68 } 69 70 if rs.Primary.ID == "" { 71 return fmt.Errorf("SES Domain Identity name not set") 72 } 73 74 domain := rs.Primary.ID 75 conn := testAccProvider.Meta().(*AWSClient).sesConn 76 77 params := &ses.GetIdentityVerificationAttributesInput{ 78 Identities: []*string{ 79 aws.String(domain), 80 }, 81 } 82 83 response, err := conn.GetIdentityVerificationAttributes(params) 84 if err != nil { 85 return err 86 } 87 88 if response.VerificationAttributes[domain] == nil { 89 return fmt.Errorf("SES Domain Identity %s not found in AWS", domain) 90 } 91 92 return nil 93 } 94 } 95 96 const testAccAwsSESDomainIdentityConfig = ` 97 resource "aws_ses_domain_identity" "test" { 98 domain = "%s.terraformtesting.com" 99 } 100 `