Skip to content

Commit

Permalink
Merge pull request #4801 from vaishakdinesh/vaishak/api-shield-operat…
Browse files Browse the repository at this point in the history
…ions

Fix: api shield tests and test data
  • Loading branch information
jacobbednarz authored Jan 9, 2025
2 parents 509230e + 87cced0 commit f02c54b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
18 changes: 8 additions & 10 deletions internal/services/api_shield_operation/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"testing"

"github.com/cloudflare/cloudflare-go"
cfv3 "github.com/cloudflare/cloudflare-go/v3"
"github.com/cloudflare/cloudflare-go/v3/api_gateway"
"github.com/cloudflare/terraform-provider-cloudflare/internal/acctest"
"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
"github.com/cloudflare/terraform-provider-cloudflare/internal/utils"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)
Expand Down Expand Up @@ -86,28 +87,25 @@ func TestAccCloudflareAPIShieldOperation_ForceNew(t *testing.T) {
}

func testAccCheckAPIShieldOperationDelete(s *terraform.State) error {
client, clientErr := acctest.SharedV1Client() // TODO(terraform): replace with SharedV2Clent
if clientErr != nil {
tflog.Error(context.TODO(), fmt.Sprintf("failed to create Cloudflare client: %s", clientErr))
}
client := acctest.SharedClient()

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

_, err := client.GetAPIShieldOperation(
_, err := client.APIGateway.Operations.Get(
context.Background(),
cloudflare.ZoneIdentifier(rs.Primary.Attributes[consts.ZoneIDSchemaKey]),
cloudflare.GetAPIShieldOperationParams{
OperationID: rs.Primary.Attributes["id"],
rs.Primary.Attributes["operation_id"],
api_gateway.OperationGetParams{
ZoneID: cfv3.F(rs.Primary.Attributes[consts.ZoneIDSchemaKey]),
},
)
if err == nil {
return fmt.Errorf("operation still exists")
}

var notFoundError *cloudflare.NotFoundError
var notFoundError *cfv3.Error
if !errors.As(err, &notFoundError) {
return fmt.Errorf("expected not found error but got: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

resource "cloudflare_api_shield_operation" "%[1]s" {
zone_id = "%[2]s"
method = "%[3]s"
host = "%[4]s"
endpoint = "%[5]s"
}
resource "cloudflare_api_shield_operation" "%[1]s" {
zone_id = "%[2]s"
method = "%[3]s"
host = "%[4]s"
endpoint = "%[5]s"
}

0 comments on commit f02c54b

Please sign in to comment.