github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/resource_circonus_check_test.go (about) 1 package circonus 2 3 import ( 4 "fmt" 5 6 "github.com/circonus-labs/circonus-gometrics/api" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 func testAccCheckDestroyCirconusCheckBundle(s *terraform.State) error { 11 c := testAccProvider.Meta().(*providerContext) 12 13 for _, rs := range s.RootModule().Resources { 14 if rs.Type != "circonus_check" { 15 continue 16 } 17 18 cid := rs.Primary.ID 19 exists, err := checkCheckBundleExists(c, api.CIDType(&cid)) 20 if err != nil { 21 return fmt.Errorf("Error checking check bundle %s", err) 22 } 23 24 if exists { 25 return fmt.Errorf("check bundle still exists after destroy") 26 } 27 } 28 29 return nil 30 } 31 32 func checkCheckBundleExists(c *providerContext, checkBundleID api.CIDType) (bool, error) { 33 cb, err := c.client.FetchCheckBundle(checkBundleID) 34 if err != nil { 35 return false, err 36 } 37 38 if api.CIDType(&cb.CID) == checkBundleID { 39 return true, nil 40 } 41 42 return false, nil 43 }