-
Notifications
You must be signed in to change notification settings - Fork 632
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
Drift in cloudflare_ruleset
for http_request_firewall_custom
phase for computed args id
, last_updated
, ref
, version
#2690
Comments
Community NoteVoting for Prioritization
Volunteering to Work on This Issue
|
Thank you for reporting this issue! For maintainers to dig into issues it is required that all issues include the entirety of This issue has been marked with |
I can provide this, but I'm not comfortable posting that here in a public forum. I'm an enterprise customer, can I create a case? Rules, IPs, etc. would take a long while to redact. Log uploaded to case id: #2901904 |
cloudflare_ruleset
for http_request_firewall_custom
phasecloudflare_ruleset
for http_request_firewall_custom
phase for computed args id
, last_updated
, ref
, version
Thanks for the lifecycle hint. It can help with perma drift until a proper solution is identified. |
Marking this issue as stale due to 30 days of inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 7 days it will automatically be closed. Maintainers can also remove the |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
@DDuarte and @nitrocode if you define a unique Edit: Spoke too soon, the issue persists. |
+1 dealing with this issue. |
I tried to fix this something like:
However there is nothing like |
@gabrielqs could you share what you use? I tried setting the |
Marking this issue as stale due to 30 days of inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 7 days it will automatically be closed. Maintainers can also remove the |
This is still a problem |
@nitrocode sorry, only seeing your message now. here's what we had to do to get around this:
It is terrible, and we need to remind ourselves to add this every time we add a new rule, but at least the drift doesn't show up on every plan |
I'm happy it works for you but that doesn't work for us. We still see the drift even with explicitly specifying each individual attributes per rule in Since these rules are all in a single terraform resource and we cannot get the plan in a reviewable state, we may have to consider moving these rules out of terraform and having them managed with a script that supplants all the rules upon pr merge. cc @jacobbednarz friendly ping to get cloudflare's feedback here. This is the 2nd highest voted issue and ideally we should be able to manage and review changes within terraform without so much noise. |
I am providing a full TF_LOG=DEBUG for 2 scenarios, both of which are problematic when working with the Cloudflare ruleset resource. Please note that while there is a workaround (manually verifying them), this is a major issue for my team with a hundred rules in a zone and could result in a bad rule change making its way into the WAF. Scenarios:
|
This comment was marked as spam.
This comment was marked as spam.
This comment has been minimized.
This comment has been minimized.
anyone got a resolution or a workaround for this? |
still an issue |
Has anyone came up with any workaround for this till it gets fixed by terraform? |
Has anyone tried using a separate terraform directory for these rules using the older 3.x provider ? https://registry.terraform.io/providers/cloudflare/cloudflare/3.35.0/docs/resources/ruleset This way you can use the 3.x only for the older ruleset resource and use the latest provider for all the other resources |
Marking this issue as stale due to 30 days of inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 7 days it will automatically be closed. Maintainers can also remove the |
This is still an issue |
I'm willing to bet that the new major version of the provider fixes this based on some of what I read here. https://blog.cloudflare.com/automatically-generating-cloudflares-terraform-provider/ Haven't tested it but I likely will in the next few days. |
Marking this issue as stale due to 30 days of inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 7 days it will automatically be closed. Maintainers can also remove the |
Go away stale bot |
got the same issue, but |
Marking this issue as stale due to 30 days of inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 7 days it will automatically be closed. Maintainers can also remove the |
bump |
Within the rulesets schema, we have a handful of fields that are `Computed`. The expectation of this directive is that it is a value not known at run time and may be provided by the remote. However, this premise will break down and not work correctly if the value is ever provided to the plan since the value is no longer "unknown". This subtle bug is one part of what is contributing to the additional output toil in #2690. To address this, I've removed the lines that modified these values and were being supplied to the plan operation. This takes the confusing and bloated output from looking like this: ``` Terraform will perform the following actions: # cloudflare_ruleset.rate_limiting_example will be updated in-place ~ resource "cloudflare_ruleset" "rate_limiting_example" { id = "87e1099f077f4e49bbfbe159217ff605" name = "restrict API requests count" # (4 unchanged attributes hidden) ~ rules { ~ id = "e3b97fdf354c4c24a7ac091c3537fbc5" -> (known after apply) ~ last_updated = "2024-01-31 04:02:55.651275 +0000 UTC" -> (known after apply) ~ ref = "e3b97fdf354c4c24a7ac091c3537fbc5" -> (known after apply) ~ version = "1" -> (known after apply) # (4 unchanged attributes hidden) # (1 unchanged block hidden) } + rules { + action = "block" + description = "rate limit for API" + enabled = true + expression = "(http.request.uri.path matches \"^/api0/\")" + id = (known after apply) + last_updated = (known after apply) + ref = (known after apply) + version = (known after apply) + ratelimit { + characteristics = [ + "cf.colo.id", + "ip.src", ] + mitigation_timeout = 600 + period = 60 + requests_per_period = 100 + requests_to_origin = false } } } Plan: 0 to add, 1 to change, 0 to destroy. ``` To a clearer and more concise output: ``` Terraform will perform the following actions: # cloudflare_ruleset.rate_limiting_example will be updated in-place ~ resource "cloudflare_ruleset" "rate_limiting_example" { id = "87e1099f077f4e49bbfbe159217ff605" name = "restrict API requests count" # (4 unchanged attributes hidden) ~ rules { id = "39ed6015367444e3905d838cadc1b9c2" + last_updated = (known after apply) + version = (known after apply) # (5 unchanged attributes hidden) # (1 unchanged block hidden) } + rules { + action = "block" + description = "rate limit for API" + enabled = true + expression = "(http.request.uri.path matches \"^/api0/\")" + id = (known after apply) + last_updated = (known after apply) + ref = (known after apply) + version = (known after apply) + ratelimit { + characteristics = [ + "cf.colo.id", + "ip.src", ] + mitigation_timeout = 600 + period = 60 + requests_per_period = 100 + requests_to_origin = false } } } Plan: 0 to add, 1 to change, 0 to destroy. ``` The second part of this confusing output is the `last_updated` and `version` output. The `last_updated` is pretty self explanatory however, there are some minor but important details about the version field here. Within ERE, it captures and is tied to a particular state of the ruleset rule at any point and is incremented when changes are detected to any parts of the rule. The nuance here is that ERE does not perform a diff of the current state and what is proposed. Instead, it autoincrements this field even if the payload is identical. So why is this important for the Terraform resource? Well, since we use explicit ordering via `ListNestedObject` schema attribute, we are sending all rules to the API even when only a single one changes to ensure we maintain the correctness the end user expects. Doing this causes the `last_updated` and `version` fields to always show as unknown values and result in updates. While the `last_updated` and `version` fields are useful in a context where you may reuse the `version`, value, it's not in Terraform. To remove that part of the diff, we're going to just remove them entirely from the schema. Given that users couldn't be using them in a configuration, we're going to release this within a minor version handling the cleanup internally to the provider. Supersedes #3091 Closes #2690
Sweet. Thank you @zakcutner for the PR and @jacobbednarz for merging and releasing. We're looking forward to using the latest version. |
Much appreciated guys! This will be awesome! |
This functionality has been released in v4.48.0 of the Terraform Cloudflare Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
Confirmation
Terraform and Cloudflare provider version
Terraform 1.5.5
Cloudflare provider 4.12.0 latest
Affected resource(s)
Terraform configuration files
Link to debug output
none
Panic output
N/A
Expected output
No perma drift
Actual output
Perma drift
Steps to reproduce
Additional factoids
This happened after we bumped the provider from 3.x to 4.x
We deleted the
cloudflare_ruleset
and reimported.If we do not make a change, we see
No changes
as expected. Any change we make, and we see a bunch of drift between rules, all affecting arguments that we do not set such asid
andversion
We have 30 something rules and we see these computed arguments changing for every rule.
in 4.12.0 cloudflare provider
In 4.7.1 cloudflare provider
We also cannot set a lifecycle ignore rule because this does not work for us
I'm told this might work but it's not scaleable. We have over 30 rules. I tried this and still see the drift!
We did not see this issue in 3.x cloudflare provider
I don't see any DiffSuppressFunc for any of the above drifted computed arguments. Unsure if the drift needs to be suppressed or if it needs to be investigated.
https://github.com/cloudflare/terraform-provider-cloudflare/blob/adbc0accaafe0df39e78fcfd61d092573e13a25d/internal/framework/service/rulesets/resource.go
References
Related issues
Related pr
From change log
The text was updated successfully, but these errors were encountered: