Skip to content
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

Merged
merged 3 commits into from
Dec 14, 2020

Conversation

mildwonkey
Copy link
Contributor

@mildwonkey mildwonkey commented Dec 11, 2020

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 state list would included expanded modules,
when given a module instance, so for e.g. list module.foo would result in resources from
module.foo[1], module.foo[0], etc.

Fixes #26191

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.
@mildwonkey mildwonkey requested a review from a team December 11, 2020 21:23
@codecov
Copy link

codecov bot commented Dec 11, 2020

Codecov Report

Merging #27268 (4f9f1ed) into master (e7db580) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
command/state_meta.go 69.36% <100.00%> (+21.66%) ⬆️
terraform/node_resource_plan.go 96.11% <0.00%> (-1.95%) ⬇️
dag/walk.go 91.54% <0.00%> (-0.71%) ⬇️
terraform/evaluate.go 52.89% <0.00%> (-0.42%) ⬇️
terraform/node_resource_apply_instance.go 52.55% <0.00%> (+2.79%) ⬆️
command/state_list.go 42.85% <0.00%> (+7.14%) ⬆️

Copy link
Contributor

@alisdair alisdair left a 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)...)
}
Copy link
Contributor

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!

@mildwonkey mildwonkey added the 0.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Dec 14, 2020
@mildwonkey
Copy link
Contributor Author

mildwonkey commented Dec 14, 2020

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.

@mildwonkey mildwonkey removed the 0.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Dec 14, 2020
@mildwonkey mildwonkey merged commit 8bab3dd into master Dec 14, 2020
@mildwonkey mildwonkey deleted the mildwonkey/b-state-list-modules branch December 14, 2020 16:07
@ghost
Copy link

ghost commented Jan 14, 2021

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.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

terraform state list with module path doesn't recognize nested modules
2 participants