-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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/jsonplan: fix bug with nested modules output #23092
Conversation
`marshalPlannedValues` builds a map of modules to their children in order to output the resource changes in a tree. The map was built from the list of resource changes. However if a module had no resources itself, and only called another module (a very normal case), that module would not get added to the map causing none of its children to be output in `planned_values`. This PR adds a walk up through a given module's ancestors to ensure that each module, even those without resources, would be added.
@mildwonkey Does this involve any open issues one should read to get context? |
// that Ancestors() returns an ordered slice, and verifies that | ||
// each one is in the map. | ||
ancestors := resource.Addr.Module.Ancestors() | ||
for i, ancestor := range ancestors[:len(ancestors)-1] { |
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.
It took me a little to understand the slicing here -- you drop the last so that you can do the i+1
, I figured. I looked at Ancestors
and it looks like this always includes the root module, so is it necessary to check that? Basically means that the first pass of this loop does what we've already done above, yes?
And if that is true, would that mean we could remove the above and just let this loop run? (this is an untested theory)
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.
Unfortunately, no. I tried a few variations and ended up with either missing or duplicate results that way.
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.
Fair enough!
@pselle yes! all the related issues are internal and from enterprise customers - I will send them to you, as I'd rather not include internal links here. |
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. |
marshalPlannedValues
builds a map of modules to their children inorder to output the resource changes in a tree. The map was built from
the list of resource changes. However if the parent module had no resources
itself , that module would not get added to the map causing none of its children to be
output in
planned_values
.This PR adds a walk up through a given module's ancestors to ensure that
each module, even those without resources, get added.
I spent much longer than I should have on this logic, and I mostly blame it on confusing naming (which I tried to improve, and added comments). While it now makes (enough) sense to me, I enthusiastically welcome variable name/comment suggestions if anything jumps out at you!