Skip to content
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

cloudflare_access_rule: add validation to discover errors during planning phase #921

Merged
merged 4 commits into from
Jan 27, 2021
Merged

cloudflare_access_rule: add validation to discover errors during planning phase #921

merged 4 commits into from
Jan 27, 2021

Conversation

freddierice
Copy link

The goal of this PR is to discover preventable mistakes during a terraform plan rather than an apply. Specifically, preventing developers from attempting to apply non /24 and /32 ip_ranges, resulting in partial changes and leaving them exposed.

I didn't create an issue because writing the code took about the same time as describing the problem. I'm open to other solutions.

@jacobbednarz
Copy link
Member

I don't mind the change, however, the test included here doesn't excercise the code path it intends to.

With the schema validation commented out, it still passes.

diff --git cloudflare/resource_cloudflare_access_rule.go cloudflare/resource_cloudflare_access_rule.go
index 910c84d..4ddd5a2 100644
--- cloudflare/resource_cloudflare_access_rule.go
+++ cloudflare/resource_cloudflare_access_rule.go
@@ -42,7 +42,7 @@ func resourceCloudflareAccessRule() *schema.Resource {
                                Required:         true,
                                ForceNew:         true,
                                DiffSuppressFunc: configurationDiffSuppress,
-                               ValidateFunc:     validateAccessRuleConfiguration,
+                               // ValidateFunc:     validateAccessRuleConfiguration,
                                Elem: &schema.Resource{
                                        Schema: map[string]*schema.Schema{
                                                "target": {
=== RUN   TestValidateAccessRuleConfigurationIPRange
--- PASS: TestValidateAccessRuleConfigurationIPRange (0.00s)
PASS
ok  	github.com/cloudflare/terraform-provider-cloudflare/cloudflare	0.471s

@freddierice
Copy link
Author

Thanks for the review! I fixed the bitmask bug and added a new test to make sure that commenting out the validator will result in a failed test.

@jacobbednarz
Copy link
Member

Nice one, thanks for this! 🥇

@jacobbednarz jacobbednarz merged commit 07377e9 into cloudflare:master Jan 27, 2021
@freddierice freddierice deleted the freddierice/access-validation branch January 27, 2021 13:17
@jacobbednarz jacobbednarz added this to the 2.18.0 milestone Jan 28, 2021
@jacobbednarz
Copy link
Member

this has been released in v2.18.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants