68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package ultradns
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/Ensighten/udnssdk"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func testAccTcpoolCheckDestroy(s *terraform.State) error {
|
|
client := testAccProvider.Meta().(*udnssdk.Client)
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "ultradns_tcpool" {
|
|
continue
|
|
}
|
|
|
|
k := udnssdk.RRSetKey{
|
|
Zone: rs.Primary.Attributes["zone"],
|
|
Name: rs.Primary.Attributes["name"],
|
|
Type: rs.Primary.Attributes["type"],
|
|
}
|
|
|
|
_, err := client.RRSets.Select(k)
|
|
if err == nil {
|
|
return fmt.Errorf("Record still exists")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccCheckUltradnsRecordExists(n string, record *udnssdk.RRSet) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No Record ID is set")
|
|
}
|
|
|
|
client := testAccProvider.Meta().(*udnssdk.Client)
|
|
k := udnssdk.RRSetKey{
|
|
Zone: rs.Primary.Attributes["zone"],
|
|
Name: rs.Primary.Attributes["name"],
|
|
Type: rs.Primary.Attributes["type"],
|
|
}
|
|
|
|
foundRecord, err := client.RRSets.Select(k)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if foundRecord[0].OwnerName != rs.Primary.Attributes["hostname"] {
|
|
return fmt.Errorf("Record not found: %+v,\n %+v\n", foundRecord, rs.Primary.Attributes)
|
|
}
|
|
|
|
*record = foundRecord[0]
|
|
|
|
return nil
|
|
}
|
|
}
|