github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/azurerm/resource_arm_dns_zone_test.go (about) 1 package azurerm 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/acctest" 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 "github.com/jen20/riviera/dns" 11 ) 12 13 func TestAccAzureRMDnsZone_basic(t *testing.T) { 14 ri := acctest.RandInt() 15 config := fmt.Sprintf(testAccAzureRMDnsZone_basic, ri, ri) 16 17 resource.Test(t, resource.TestCase{ 18 PreCheck: func() { testAccPreCheck(t) }, 19 Providers: testAccProviders, 20 CheckDestroy: testCheckAzureRMDnsZoneDestroy, 21 Steps: []resource.TestStep{ 22 resource.TestStep{ 23 Config: config, 24 Check: resource.ComposeTestCheckFunc( 25 testCheckAzureRMDnsZoneExists("azurerm_dns_zone.test"), 26 ), 27 }, 28 }, 29 }) 30 } 31 32 func testCheckAzureRMDnsZoneExists(name string) resource.TestCheckFunc { 33 return func(s *terraform.State) error { 34 // Ensure we have enough information in state to look up in API 35 rs, ok := s.RootModule().Resources[name] 36 if !ok { 37 return fmt.Errorf("Not found: %s", name) 38 } 39 40 conn := testAccProvider.Meta().(*ArmClient).rivieraClient 41 42 readRequest := conn.NewRequestForURI(rs.Primary.ID) 43 readRequest.Command = &dns.GetDNSZone{} 44 45 readResponse, err := readRequest.Execute() 46 if err != nil { 47 return fmt.Errorf("Bad: GetDNSZone: %s", err) 48 } 49 if !readResponse.IsSuccessful() { 50 return fmt.Errorf("Bad: GetDNSZone: %s", readResponse.Error) 51 } 52 53 return nil 54 } 55 } 56 57 func testCheckAzureRMDnsZoneDestroy(s *terraform.State) error { 58 conn := testAccProvider.Meta().(*ArmClient).rivieraClient 59 60 for _, rs := range s.RootModule().Resources { 61 if rs.Type != "azurerm_dns_zone" { 62 continue 63 } 64 65 readRequest := conn.NewRequestForURI(rs.Primary.ID) 66 readRequest.Command = &dns.GetDNSZone{} 67 68 readResponse, err := readRequest.Execute() 69 if err != nil { 70 return fmt.Errorf("Bad: GetDNSZone: %s", err) 71 } 72 73 if readResponse.IsSuccessful() { 74 return fmt.Errorf("Bad: DNS zone still exists: %s", readResponse.Error) 75 } 76 } 77 78 return nil 79 } 80 81 var testAccAzureRMDnsZone_basic = ` 82 resource "azurerm_resource_group" "test" { 83 name = "acctestRG_%d" 84 location = "West US" 85 } 86 resource "azurerm_dns_zone" "test" { 87 name = "acctestzone%d.com" 88 resource_group_name = "${azurerm_resource_group.test.name}" 89 } 90 `