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
Preserve rule IDs when updating rulesets #2172
Conversation
24d8b9c
to
cf5b6bb
Compare
changelog detected ✅ |
a27991b
to
eda2594
Compare
6c3b4c1
to
cef041b
Compare
cef041b
to
bad5330
Compare
thanks for this one @cjolowicz 💯 all acceptance tests are passing.
|
thanks @jacobbednarz 🚀 |
This functionality has been released in v3.34.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! |
This PR improves updating
cloudflare_ruleset
resources to preserve the IDs of unmodified rules. Currently, when we update a ruleset, every rule is created from scratch and all rule IDs change. We can avoid that by including the IDs of rules that haven't been modified in the request body.The implementation uses ResourceData.GetChange to retrieve the old and new values of the ruleset. Each rule in the two versions of the ruleset is serialized to JSON. We build a map to associate the JSON of each old rule with its ID. The map allows us to look up the new rules and find their IDs if they didn't change.
A ruleset can have rules that are identical except for their ID. We exclude the ID from the JSON lookup key and allow lookup keys to be associated with multiple IDs. We preserve the order of these IDs to ensure that each copy of a rule keeps its original ID.
Note: This PR extracts two functions from a large code region, which makes the overall diff hard to read. I've separated these refactorings into
refactor:
commits to make the PR easier to review. The core changes are in the singlefeat:
commit.