-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resources: WAF: handles properly when the target has been deleted on Cloudflare's side #623
resources: WAF: handles properly when the target has been deleted on Cloudflare's side #623
Conversation
…Cloudflare's side In the previous situation, when the target had been deleted, the Read accion would fail and return an error. However, this would be expected that when this happen, the object should be considered as not existing anymore and the process should continue. This thus fixes that and makes sure that we avoid erroring out when a WAF Rule, Group or Package has been deleted on Cloudflare's side.
Overall I like the simplicity of this error checking and handling however I wonder if we could be more idiomatic and use the error interface type to have this hang of the error instead of a generic method? const (
CLOUDFLARE_INVALID_OR_REMOVED_WAF_PACKAGE_ERROR_ID = 1002
CLOUDFLARE_INVALID_OR_REMOVED_WAF_RULE_ERROR_ID = 1003
)
func (r *Error) IsCloudflareWAFErrorCode() bool {
// code from `cloudflareErrorIsOneOfCodes` can go here referencing the constants from above
}
// ... example code in file
group, err := client.WAFGroup(zoneID, packageID, groupID)
if err != nil {
if err.IsCloudflareWAFErrorCode() {
d.SetId("")
return nil
}
return err
} What do you think? |
I thought about doing it specifically for WAF (in general) at the beginning but:
However, it's true that I would agree that using the error interface type could be nicer. So maybe I could:
This would take advantage of cleaner method names, while not creating a too general approach, that can thus easily be reused for other resources in the future if needed. Thoughts? |
I think that's a reasonable compromise and gets us into a better place, +1 to seeing it in action. Thanks! |
Will make the changes tomorrow! |
Apparently, and that seems to have been my original reason for doing a function taking parameters instead of the error interface (I remember trying it and then going the other way), but it's seems it is not possible to do: Would we want to implement that on the error subtype, hence requiring casting when making the call? Feels to me it might be less readable if we chose to do so? :( |
@@ -9,6 +9,8 @@ import ( | |||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | |||
) | |||
|
|||
const CLOUDFLARE_INVALID_OR_REMOVED_WAF_RULE_SET_ID_ERROR = 1003 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I put those into their own file or is that fine to have per-file constants here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to start here and we can always extract them out and DRY them up if needed.
@XaF I think this in a better place; I wouldn't want better to get in the way of perfect here. We can always explore the |
Perfect then! |
All good! Just waiting on integration to complete and I'll squash and merge. |
In the previous situation, when the target had been deleted, the Read
accion would fail and return an error. However, this would be expected
that when this happen, the object should be considered as not existing
anymore and the process should continue. This thus fixes that and makes
sure that we avoid erroring out when a WAF Rule, Group or Package has
been deleted on Cloudflare's side.