github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/ultradns/common_test.go (about) 1 package ultradns 2 3 import ( 4 "fmt" 5 6 "github.com/Ensighten/udnssdk" 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func testAccRdpoolCheckDestroy(s *terraform.State) error { 12 client := testAccProvider.Meta().(*udnssdk.Client) 13 14 for _, rs := range s.RootModule().Resources { 15 if rs.Type != "ultradns_rdpool" { 16 continue 17 } 18 19 k := udnssdk.RRSetKey{ 20 Zone: rs.Primary.Attributes["zone"], 21 Name: rs.Primary.Attributes["name"], 22 Type: rs.Primary.Attributes["type"], 23 } 24 25 _, err := client.RRSets.Select(k) 26 if err == nil { 27 return fmt.Errorf("Record still exists") 28 } 29 } 30 31 return nil 32 } 33 34 func testAccTcpoolCheckDestroy(s *terraform.State) error { 35 client := testAccProvider.Meta().(*udnssdk.Client) 36 37 for _, rs := range s.RootModule().Resources { 38 if rs.Type != "ultradns_tcpool" { 39 continue 40 } 41 42 k := udnssdk.RRSetKey{ 43 Zone: rs.Primary.Attributes["zone"], 44 Name: rs.Primary.Attributes["name"], 45 Type: rs.Primary.Attributes["type"], 46 } 47 48 _, err := client.RRSets.Select(k) 49 if err == nil { 50 return fmt.Errorf("Record still exists") 51 } 52 } 53 54 return nil 55 } 56 57 func testAccCheckUltradnsRecordExists(n string, record *udnssdk.RRSet) resource.TestCheckFunc { 58 return func(s *terraform.State) error { 59 rs, ok := s.RootModule().Resources[n] 60 61 if !ok { 62 return fmt.Errorf("Not found: %s", n) 63 } 64 65 if rs.Primary.ID == "" { 66 return fmt.Errorf("No Record ID is set") 67 } 68 69 client := testAccProvider.Meta().(*udnssdk.Client) 70 k := udnssdk.RRSetKey{ 71 Zone: rs.Primary.Attributes["zone"], 72 Name: rs.Primary.Attributes["name"], 73 Type: rs.Primary.Attributes["type"], 74 } 75 76 foundRecord, err := client.RRSets.Select(k) 77 78 if err != nil { 79 return err 80 } 81 82 if foundRecord[0].OwnerName != rs.Primary.Attributes["hostname"] { 83 return fmt.Errorf("Record not found: %+v,\n %+v\n", foundRecord, rs.Primary.Attributes) 84 } 85 86 *record = foundRecord[0] 87 88 return nil 89 } 90 }