core: -target option to also select resources in descendant modules #15314
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.
(This is adapted from #9236, originally submitted by @uhef. It is rebased and altered slightly in approach to be compatible with other changes that were made to
ResourceAddress
since the original PR was submitted.)Previously the behavior for
-target
when given a module address was to target only resources directly within that module, ignoring any resources defined in child modules.This behavior turned out to be counter-intuitive, since users expected the
-target
address to be interpreted hierarchically.We'll now use a new
Contains
function for addresses, which provides a hierarchical "containment" concept that is more consistent with user expectations. In particular, it allowsmodule.foo
to matchmodule.foo.module.bar.aws_instance.baz
, where before this would not have matched.Since
Contains
isn't commutative (unlikeEquals
) this requires some special handling for targeting specific resource indices. When given an argument like-target=aws_instance.foo[0]
, the initial graph construction (for both plan and refresh) is for the resource nodes from configuration, whichhave not yet been expanded to separate indexed instances. Thus we need to do the first pass of
TargetsTransformer
in mode where indices are ignored, with the work then completed in theDynamicExpand
method by re-applying theTargetsTransformer
in index-sensitive mode within the dynamic subgraph.This is a breaking change for anyone depending on the previous behavior of
-target
, since it will now select more resources than before. There is no way provided to obtain the previous behavior. Eventually we may support negative targeting, which could then combine with positive targets to regain the previous behavior as an explicit choice.This addresses #5190.
This change intended to land in 0.10 so we can properly announce the breaking change in targeting behavior as part of that release.