github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/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 testAccTcpoolCheckDestroy(s *terraform.State) error { 12 client := testAccProvider.Meta().(*udnssdk.Client) 13 14 for _, rs := range s.RootModule().Resources { 15 if rs.Type != "ultradns_tcpool" { 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 testAccCheckUltradnsRecordExists(n string, record *udnssdk.RRSet) resource.TestCheckFunc { 35 return func(s *terraform.State) error { 36 rs, ok := s.RootModule().Resources[n] 37 38 if !ok { 39 return fmt.Errorf("Not found: %s", n) 40 } 41 42 if rs.Primary.ID == "" { 43 return fmt.Errorf("No Record ID is set") 44 } 45 46 client := testAccProvider.Meta().(*udnssdk.Client) 47 k := udnssdk.RRSetKey{ 48 Zone: rs.Primary.Attributes["zone"], 49 Name: rs.Primary.Attributes["name"], 50 Type: rs.Primary.Attributes["type"], 51 } 52 53 foundRecord, err := client.RRSets.Select(k) 54 55 if err != nil { 56 return err 57 } 58 59 if foundRecord[0].OwnerName != rs.Primary.Attributes["hostname"] { 60 return fmt.Errorf("Record not found: %+v,\n %+v\n", foundRecord, rs.Primary.Attributes) 61 } 62 63 *record = foundRecord[0] 64 65 return nil 66 } 67 }