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/jsonstate: fix inconsistency with resource address #24256

Merged
merged 3 commits into from
Mar 5, 2020

Conversation

mildwonkey
Copy link
Contributor

Resource addresses in state output were not including index for
instances created with for_each or count, while the index was appearing
in the plan output. This PR fixes that inconsistency, adds tests, and
updates the existing tests.

Fixes #24110

Resource addresses in state output were not including index for
instances created with for_each or count, while the index was appearing
in the plan output. This PR fixes that inconsistency, adds tests, and
updates the existing tests.

Fixes #24110
@mildwonkey mildwonkey requested review from vancluever and a team March 3, 2020 15:40
Copy link
Contributor

@vancluever vancluever left a comment

Choose a reason for hiding this comment

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

@mildwonkey thanks for looking into this!

The only feedback I think I can offer as someone who is not diving into this code on a regular basis is maybe we could get some degree of static fixture testing here to express testing of the final product in "layman's terms"... ie: less meta-code in the tests and more actual JSON.

Otherwise I'm guessing this looks good and I'll probably see it when we update the test fixtures in the Sentinel items 🙂

@mildwonkey
Copy link
Contributor Author

@vancluever that makes sense! The end to end tests, which include config and expected json output, are in the command package: https://github.com/hashicorp/terraform/tree/master/command/testdata/show-json

Does that cover your request? I can (and will) go add a few more complicated examples that include resources created with for_each and count - and let me know if there's anything else you think is missing from those examples.

@vancluever
Copy link
Contributor

Yeah e2e would be the prefect place. Did these not need modifying in their current form?

@mildwonkey
Copy link
Contributor Author

The e2e tests did not need updates because none of them used (non-empty) prior state, and the state output is where the non-instanced addressing appeared. (I am adding to that now)

@mildwonkey mildwonkey force-pushed the mildwonkey/json-state-resource-addr branch from a16a753 to 095bf22 Compare March 3, 2020 18:05
@mwhooker
Copy link
Contributor

mwhooker commented Mar 3, 2020

exciting! Unfortunately I'm unable to test beyond the example in my report, because I just have a json file that reproduces the more complex issue.

"root_module": {
"resources": [
{
"address": "test_instance.test[0]",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mwhooker I believe this is the important test for you :) And thank you again for reporting the bug!

Copy link
Contributor

Choose a reason for hiding this comment

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

this looks good! It looks like the code covers this case, but there's also the issue of modules getting lost. I wonder if that's worth capturing in a test? up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the issue of modules getting lost
Sorry, that's not ringing any bells - is there a related GH issue?

There are e2e tests that cover modules in configuration, but not prior state. I'll add (at least) one, and if you can share the module issue I can tailor a test to that specifically.

@codecov
Copy link

codecov bot commented Mar 3, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@430b7c8). Click here to learn what that means.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #24256   +/-   ##
=========================================
  Coverage          ?   57.33%           
=========================================
  Files             ?      656           
  Lines             ?    59835           
  Branches          ?        0           
=========================================
  Hits              ?    34304           
  Misses            ?    22486           
  Partials          ?     3045
Impacted Files Coverage Δ
command/jsonstate/state.go 40.81% <50%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 430b7c8...74a2b46. Read the comment docs.

Copy link
Contributor

@vancluever vancluever left a comment

Choose a reason for hiding this comment

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

I think @mwhooker has validated the fix 🙂 thanks again for including these @mildwonkey!

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.

This changeset makes sense to me, and the new e2e tests explains its effect very clearly 👏

@mildwonkey mildwonkey merged commit 7f1b0a4 into master Mar 5, 2020
@mildwonkey mildwonkey deleted the mildwonkey/json-state-resource-addr branch March 5, 2020 13:13
@ghost
Copy link

ghost commented Apr 5, 2020

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 Apr 5, 2020
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.

Resource addresses in prior state of a json plan lacking indexes
4 participants