-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
command/state list: list resources in nested and expanded modules #27268
Conversation
A few distinct bugs fixed in here: There was a bug in the logic checking if a given module was the child of the targetAddr, now fixed. That resolved the basic issue where resources in nested submodules were not listed. The logic around allowMissing needed some tweaking to allow for empty modules, as long as those modules had submodules with resources. state list is the only command using allowMissing with false so this felt safe to do. Finally I extended the logic so list would included expanded modules, which is to say giving module.foo would result in resources from module.foo[1], module.foo[0], etc.
Codecov Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! 👍
While not essential, I think we might want to update the state list
docs, specifically this section about filtering by module. It'd be nice to be clear about the fact that Terraform lists all descendent resources, not just in the given module.
if addr.IsAncestor(cms.Addr) || addr.TargetContains(cms.Addr) { | ||
found = true | ||
ret = append(ret, c.collectModuleResourceInstances(cms)...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this a lot more than the slice based approach!
Ah, thanks for pointing that out @alisdair . The behavior is covered by the resource addressing docs and I hadn't noticed the difference between that page and the main state list documentation. Unfortunately (but I'm grateful to know!) that also reinforces this PR as an awkward combination bugfix/ breaking change, so I'm also going to remove the backport label which I just added. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
A few distinct bugs fixed in here:
There was a bug in the logic checking if a given module was the child of
the targetAddr, now fixed. That resolved the basic issue where resources
in nested submodules were not listed.
The logic around
allowMissing
needed some tweaking to allow for emptymodules, as long as those modules had submodules with resources.
state list
is the only command usingallowMissing
withfalse
, so this felt safeto do.
Finally I extended the logic so
state list
would included expanded modules,when given a module instance, so for e.g.
list module.foo
would result in resources frommodule.foo[1]
,module.foo[0]
, etc.Fixes #26191