Backport of Generalize the idea of a "plan mode", vs just destroy flag into v0.15 #28529
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.
Backport
This PR is auto-generated from #28489 to be assessed for backporting due to the inclusion of the label 0.15-backport.
The below text is copied from the body of the original PR.
Previously there were only two planning modes: normal mode and destroy mode. In that context it made sense for these to be distinguished only by a boolean flag.
We're now getting ready to add our third mode, "refresh only". This establishes the idea that planning can be done in one of a number of mutually-exclusive "modes", which are related to but separate from the various other options that serve as modifiers for the plan operation.
This commit only introduces the new
plans.Mode
type and replaces the existing "destroy" flag fields with a field of that type. This doesn't cause any change in effective behavior because Terraform Core still supports onlyNormalMode
andDestroyMode
, withNewContext
rejecting an attempt to create aRefreshMode
context for now, and the CLI layer having no codepath that tries to set it.It is in retrospect a little odd that the "destroy" flag was part of
ContextOpts
rather than just an argument to thePlan
method, but refactoring that would be too invasive a change for right now so we'll leave this as a field of the context for now and save revisiting that for another day.For this PR I've just peeled off the first two commits from #28297. These two just change internal implementation details of how we represent destroy mode without adding any new functionality. I want to land these first and early because they are cross-cutting and thus likely to come into conflict with other work if they were part of a long-lived feature branch.
With these in place the remaining work should involve more localized commits that we can land without necessarily colliding with other work in other subsystems.
I've marked this for backport primarily because otherwise it seems likely that other unrelated backports to v0.15 will end up failing due to this being a cross-cutting change. However, it also seems likely that at least parts of the planned functionality for refresh-only plans will also land in the v0.15 branch, and so this backport will support that.