Skip to content

Commit

Permalink
fix not-found case
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursnerdly committed Dec 13, 2024
1 parent 8b7940f commit 533c324
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cyral/internal/policy/policywizards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ data "cyral_policy_wizards" "wizard_list" {
`,
Check: checkOneWizard(dsName, "data-firewall"),
},
{
Config: `
data "cyral_policy_wizards" "wizard_list" {
wizard_id = "XXX"
}
`,
Check: resource.TestCheckResourceAttr(dsName, "wizards.#", "0"),
},
},
})
}
Expand Down
8 changes: 6 additions & 2 deletions cyral/internal/policyset/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
methods "buf.build/gen/go/cyral/policy/grpc/go/policy/v1/policyv1grpc"
msg "buf.build/gen/go/cyral/policy/protocolbuffers/go/policy/v1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cyralinc/terraform-provider-cyral/cyral/client"
"github.com/cyralinc/terraform-provider-cyral/cyral/utils"
Expand Down Expand Up @@ -177,10 +179,12 @@ func readPolicyWizards(ctx context.Context, cl *client.Client, rd *schema.Resour
Id: wizId,
}
resp, err := grpcClient.ReadPolicyWizard(ctx, req)
if err != nil {
if err != nil && status.Code(err) != codes.NotFound {
return err
}
wizardList = []*msg.PolicyWizard{resp.GetPolicyWizard()}
if status.Code(err) != codes.NotFound {
wizardList = []*msg.PolicyWizard{resp.GetPolicyWizard()}
}
} else {
req := &msg.ListPolicyWizardsRequest{}
resp, err := grpcClient.ListPolicyWizards(ctx, req)
Expand Down

0 comments on commit 533c324

Please sign in to comment.