Support lifecycle.ignore_changes in module calls using self selectors#38184
Draft
LorDima wants to merge 2 commits intohashicorp:mainfrom
Draft
Support lifecycle.ignore_changes in module calls using self selectors#38184LorDima wants to merge 2 commits intohashicorp:mainfrom
LorDima wants to merge 2 commits intohashicorp:mainfrom
Conversation
cac50eb to
7f8a220
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #27360
Summary
This PR adds support for
lifecycle { ignore_changes = ... }insidemoduleblocks.The module call’s
ignore_changesrules are applied to managed resources created by that module call, using aself-based selector to reference resources inside the called module.Why
self?Module calls can use
countorfor_each, which means a singlemoduleblock can expand into multiple module instances. A module-call lifecycle rule therefore needs a way to either:The
selfkeyword provides a compact and readable way to express both:self.<type>.<name>.<attr>applies to all instances of the module callself[<key>].<type>.<name>.<attr>filters to one instance when the module call is expanded viacount/for_eachThis avoids introducing a new addressing scheme and keeps the rule anchored to “resources inside this module call”.
User-visible behavior
Basic usage:
This causes Terraform to ignore changes to the selected attribute(s) for matching resources inside the module.
When the module call uses count / for_each, you can optionally filter by module instance key:
If the module key/index is not specified, changes to all matching
<type>.<name>.<attr>across all module instances are ignored.More granular attribute paths work as well:
Notes
These rules affect managed resources only (resource blocks), consistent with existing
ignore_changessemantics.ignore_changes = allon a module call applies to all managed resources under that module call.As with resource-level
ignore_changes, rules are evaluated against the resource schema and ignore only the specified attribute paths.Implementation details
Module-call lifecycle decoding is implemented in internal/configs via a dedicated module-call lifecycle schema (rather than reusing the resource lifecycle schema).
Module-call ignore rules are applied at resource instance evaluation time, so that module instance keys are available and self["key"] filtering works reliably for count/for_each.
The implementation merges module-call ignore rules into the resource instance’s existing ignore_changes behavior and reuses Terraform’s existing ignore_changes processing logic (rather than duplicating diff logic).
Tests
go test ./...succeedManual tests:
self.<type>.<name>.<attr>applies across all module instancesself["key"].<type>.<name>.<attr>filters a singlefor_eachinstance