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: "terraform show" to render plans like "terraform plan" #23292

Merged
merged 2 commits into from
Nov 6, 2019

Conversation

apparentlymart
Copy link
Contributor

During the Terraform 0.12 work we briefly had a partial update of the old Terraform 0.11 (and prior) diff renderer that could work with the new plan structure, but could produce only partial results.

We switched to the new plan implementation prior to release, but the terraform show command was left calling into the old partial implementation, and thus produced incomplete results when rendering a saved plan.

Here we instead use the plan rendering logic from the terraform plan command, making the output of both identical.

This fixes #23106.


Unfortunately, due to the current backend architecture that logic lives inside the backend/local, and it contains some business logic around state and schema wrangling that would make it inappropriate to move wholesale into the command/format package. To allow for a low-risk fix to the terraform show output, here we avoid some more severe refactoring by just exporting the rendering functionality in a way that allows the terraform show command to call into it.

In future we'd like to move all of the code that actually writes to the output into the command package so that the roles of these components are better segregated, but that is too big a change to block fixing this issue.


This also left lots of dead code in command/format for the old and mostly-broken plan renderer. In order to reduce naming confusion in the command/format package I've removed plan.go entirely after removing the one function that was still used from there (DiffActionSymbol) into diff.go.

During the Terraform 0.12 work we briefly had a partial update of the old
Terraform 0.11 (and prior) diff renderer that could work with the new
plan structure, but could produce only partial results.

We switched to the new plan implementation prior to release, but the
"terraform show" command was left calling into the old partial
implementation, and thus produced incomplete results when rendering a
saved plan.

Here we instead use the plan rendering logic from the "terraform plan"
command, making the output of both identical.

Unfortunately, due to the current backend architecture that logic lives
inside the local backend package, and it contains some business logic
around state and schema wrangling that would make it inappropriate to move
wholesale into the command/format package. To allow for a low-risk fix to
the "terraform show" output, here we avoid some more severe refactoring by
just exporting the rendering functionality in a way that allows the
"terraform show" command to call into it.

In future we'd like to move all of the code that actually writes to the
output into the "command" package so that the roles of these components
are better segregated, but that is too big a change to block fixing this
issue.
This "Plan" type, along with the other types it directly or indirectly
embeds and the associated functions, are adaptations of the
flatmap-oriented plan renderer logic from Terraform 0.11 and prior.

The current diff rendering logic is in diff.go, and so the contents of the
plan.go file are defunct apart from the DiffActionSymbol function that
both implementations share. Therefore here we move DiffActionSymbol into
diff.go and then remove plan.go entirely, in the interests of dead code
removal.
@apparentlymart apparentlymart added bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases labels Nov 6, 2019
@apparentlymart apparentlymart requested a review from a team November 6, 2019 01:26
@apparentlymart apparentlymart self-assigned this Nov 6, 2019
@ghost ghost added the sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK label Nov 6, 2019
@apparentlymart apparentlymart merged commit d0cbbb6 into master Nov 6, 2019
@apparentlymart apparentlymart deleted the b-cmd-show-incomplete branch November 6, 2019 14:53
// can call into it, but we're leaving it here for now in order to avoid
// disruptive refactoring.
//
// If you find yourself wanting to call this function from a third callsite,
Copy link
Contributor

Choose a reason for hiding this comment

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

I love this comment

@remipichon
Copy link

Thank you ! That was quick, hats off to you.

@ghost
Copy link

ghost commented Mar 29, 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 Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug cli sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

terraform show on v0.12 only display resource addresses
4 participants