plans/planfile: Read state snapshots as part of reading a plan #28653
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our model for
plans/planfile
has unfortunately grown inconsistent with changes to our modeling ofplans.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" toplans.Plan
for similar reasons.Unfortunately as a result of that modeling drift our
ReadPlan
method was silently producing an incompleteplans.Plan
object, causing use-cases liketerraform 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.