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/jsonplan: fix bug with nested modules output #23092

Merged
merged 1 commit into from
Oct 17, 2019

Conversation

mildwonkey
Copy link
Contributor

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 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!

`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 mildwonkey requested a review from a team October 16, 2019 16:19
@pselle
Copy link
Contributor

pselle commented Oct 17, 2019

@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] {
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough!

@mildwonkey
Copy link
Contributor Author

@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.

@mildwonkey mildwonkey merged commit 4b10a6e into master Oct 17, 2019
@ghost
Copy link

ghost commented Nov 17, 2019

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 and limited conversation to collaborators Nov 17, 2019
@mildwonkey mildwonkey deleted the mildwonkey/b-jsonplan-nested-modules branch November 19, 2019 16:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants