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

plans/planfile: Read state snapshots as part of reading a plan #28653

Merged
merged 1 commit into from
May 10, 2021

Conversation

apparentlymart
Copy link
Contributor

Our model for plans/planfile has unfortunately grown inconsistent with changes to our modeling of plans.Plan.

Originally we considered the plan "header" and the planned changes as an entirely separate artifact from the prior state, but we later realized that carrying the prior state around with the plan is important to ensuring we always have enough context to faithfully render a plan to the user, and so we added the prior state as a field of plans.Plan. More recently we've also added the "previous run state" to plans.Plan for similar reasons.

Unfortunately as a result of that modeling drift our ReadPlan method was silently producing an incomplete plans.Plan object, causing use-cases like terraform show to produce slightly different results due to the plan object not round-tripping completely.

As a short-term tactical fix, here we add state snapshot reading into the ReadPlan function. This is not an ideal solution because it means that in the case of applying a plan, where we really do need access to the state file, we'll end up reading the prior state file twice. However, the goal here is only to heal the modelling quirk with as little change as possible, because we're not currently at a point where we'd be willing to risk regressions from a larger refactoring.


I came across this while working on #28634. Without the changes from that PR the discrepancies aren't a big deal for terraform show yet, but I wanted to submit this separately anyway because that PR is getting kinda bulky and this bug isn't directly related to it.

Our model for plans/planfile has unfortunately grown inconsistent with
changes to our modeling of plans.Plan.

Originally we considered the plan "header" and the planned changes as an
entirely separate artifact from the prior state, but we later realized
that carrying the prior state around with the plan is important to
ensuring we always have enough context to faithfully render a plan to the
user, and so we added the prior state as a field of plans.Plan.
More recently we've also added the "previous run state" to plans.Plan for
similar reasons.

Unfortunately as a result of that modeling drift our ReadPlan method was
silently producing an incomplete plans.Plan object, causing use-cases like
"terraform show" to produce slightly different results due to the
plan object not round-tripping completely.

As a short-term tactical fix, here we add state snapshot reading into the
ReadPlan function. This is not an ideal solution because it means that
in the case of applying a plan, where we really do need access to the
state _file_, we'll end up reading the prior state file twice. However,
the goal here is only to heal the modelling quirk with as little change
as possible, because we're not currently at a point where we'd be willing
to risk regressions from a larger refactoring.
@apparentlymart apparentlymart requested a review from a team May 7, 2021 23:42
@apparentlymart apparentlymart self-assigned this May 7, 2021
@apparentlymart apparentlymart added the 0.15-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label May 8, 2021
@apparentlymart apparentlymart removed the 0.15-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label May 10, 2021
@apparentlymart apparentlymart merged commit 0f936b9 into main May 10, 2021
@apparentlymart apparentlymart deleted the b-planfile-states branch May 10, 2021 16:22
@apparentlymart
Copy link
Contributor Author

Backported to v0.15 as 7a6c1a3

@github-actions
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 10, 2021
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.

2 participants