Skip to content

Commit

Permalink
add testAccCheckCloudflareAccessApplicationDestroy method
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Jul 12, 2020
1 parent 639bd3d commit 2cbf26d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions cloudflare/resource_cloudflare_access_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"os"
"testing"

"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

var (
Expand All @@ -22,7 +24,7 @@ func TestAccCloudflareAccessApplicationBasic(t *testing.T) {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudflareAccessGroupDestroy,
CheckDestroy: testAccCheckCloudflareAccessApplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudflareAccessApplicationConfigBasic(rnd, zoneID, domain),
Expand All @@ -47,7 +49,7 @@ func TestAccCloudflareAccessApplicationWithCORS(t *testing.T) {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudflareAccessGroupDestroy,
CheckDestroy: testAccCheckCloudflareAccessApplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudflareAccessApplicationConfigWithCORS(rnd, zoneID, domain),
Expand Down Expand Up @@ -93,3 +95,20 @@ resource "cloudflare_access_application" "%[1]s" {
}
`, rnd, zoneID, domain)
}

func testAccCheckCloudflareAccessApplicationDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*cloudflare.API)

for _, rs := range s.RootModule().Resources {
if rs.Type != "cloudflare_access_application" {
continue
}

_, err := client.AccessApplication(rs.Primary.Attributes["zone_id"], rs.Primary.ID)
if err == nil {
return fmt.Errorf("AccessApplication still exists")
}
}

return nil
}

0 comments on commit 2cbf26d

Please sign in to comment.