github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/builtin/providers/aws/resource_aws_route53_zone_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestAccRoute53Zone(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 CheckDestroy: testAccCheckRoute53ZoneDestroy, 16 Steps: []resource.TestStep{ 17 resource.TestStep{ 18 Config: testAccRoute53ZoneConfig, 19 Check: resource.ComposeTestCheckFunc( 20 testAccCheckRoute53ZoneExists("aws_route53_zone.main"), 21 ), 22 }, 23 }, 24 }) 25 } 26 27 func testAccCheckRoute53ZoneDestroy(s *terraform.State) error { 28 conn := testAccProvider.Meta().(*AWSClient).route53 29 for _, rs := range s.RootModule().Resources { 30 if rs.Type != "aws_route53_zone" { 31 continue 32 } 33 34 _, err := conn.GetHostedZone(rs.Primary.ID) 35 if err == nil { 36 return fmt.Errorf("Hosted zone still exists") 37 } 38 } 39 return nil 40 } 41 42 func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc { 43 return func(s *terraform.State) error { 44 rs, ok := s.RootModule().Resources[n] 45 if !ok { 46 return fmt.Errorf("Not found: %s", n) 47 } 48 49 if rs.Primary.ID == "" { 50 return fmt.Errorf("No hosted zone ID is set") 51 } 52 53 conn := testAccProvider.Meta().(*AWSClient).route53 54 _, err := conn.GetHostedZone(rs.Primary.ID) 55 if err != nil { 56 return fmt.Errorf("Hosted zone err: %v", err) 57 } 58 return nil 59 } 60 } 61 62 const testAccRoute53ZoneConfig = ` 63 resource "aws_route53_zone" "main" { 64 name = "hashicorp.com" 65 } 66 `