mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-05-20 12:02:01 -04:00
New plans.Quality type for display-relevant facts about a plan
This commit replaces the existing jsonformat.PlanRendererOpt type with a new type with identical semantics, located in the plans package. We needed to be able to exchange the facts represented by `jsonformat.PlanRendererOpt` across some package boundaries, but the jsonformat package is implicated in too many dependency chains to be safe for that purpose! So, we had to make a new one. The plans package seems safe to import from all the places that must emit or accept this info, and already contains plans.Mode, which is effectively a sibling of this type.
This commit is contained in:
committed by
Sebastian Rivera
parent
da963a13b9
commit
0df3c143bb
@@ -19,14 +19,9 @@ import (
|
||||
"github.com/hashicorp/terraform/internal/plans"
|
||||
)
|
||||
|
||||
type PlanRendererOpt int
|
||||
|
||||
const (
|
||||
detectedDrift string = "drift"
|
||||
proposedChange string = "change"
|
||||
|
||||
Errored PlanRendererOpt = iota
|
||||
CanNotApply
|
||||
)
|
||||
|
||||
type Plan struct {
|
||||
@@ -51,8 +46,8 @@ func (plan Plan) getSchema(change jsonplan.ResourceChange) *jsonprovider.Schema
|
||||
}
|
||||
}
|
||||
|
||||
func (plan Plan) renderHuman(renderer Renderer, mode plans.Mode, opts ...PlanRendererOpt) {
|
||||
checkOpts := func(target PlanRendererOpt) bool {
|
||||
func (plan Plan) renderHuman(renderer Renderer, mode plans.Mode, opts ...plans.Quality) {
|
||||
checkOpts := func(target plans.Quality) bool {
|
||||
for _, opt := range opts {
|
||||
if opt == target {
|
||||
return true
|
||||
@@ -102,7 +97,7 @@ func (plan Plan) renderHuman(renderer Renderer, mode plans.Mode, opts ...PlanRen
|
||||
// the plan is "applyable" and, if so, whether it had refresh changes
|
||||
// that we already would've presented above.
|
||||
|
||||
if checkOpts(Errored) {
|
||||
if checkOpts(plans.Errored) {
|
||||
if haveRefreshChanges {
|
||||
renderer.Streams.Print(format.HorizontalRule(renderer.Colorize, renderer.Streams.Stdout.Columns()))
|
||||
renderer.Streams.Println()
|
||||
@@ -143,7 +138,7 @@ func (plan Plan) renderHuman(renderer Renderer, mode plans.Mode, opts ...PlanRen
|
||||
)
|
||||
|
||||
if haveRefreshChanges {
|
||||
if !checkOpts(CanNotApply) {
|
||||
if !checkOpts(plans.NoChanges) {
|
||||
// In this case, applying this plan will not change any
|
||||
// remote objects but _will_ update the state to match what
|
||||
// we detected during refresh, so we'll reassure the user
|
||||
@@ -210,7 +205,7 @@ func (plan Plan) renderHuman(renderer Renderer, mode plans.Mode, opts ...PlanRen
|
||||
}
|
||||
|
||||
if len(changes) > 0 {
|
||||
if checkOpts(Errored) {
|
||||
if checkOpts(plans.Errored) {
|
||||
renderer.Streams.Printf("\nTerraform planned the following actions, but then encountered a problem:\n")
|
||||
} else {
|
||||
renderer.Streams.Printf("\nTerraform will perform the following actions:\n")
|
||||
|
||||
@@ -82,7 +82,7 @@ type Renderer struct {
|
||||
RunningInAutomation bool
|
||||
}
|
||||
|
||||
func (renderer Renderer) RenderHumanPlan(plan Plan, mode plans.Mode, opts ...PlanRendererOpt) {
|
||||
func (renderer Renderer) RenderHumanPlan(plan Plan, mode plans.Mode, opts ...plans.Quality) {
|
||||
if incompatibleVersions(jsonplan.FormatVersion, plan.PlanFormatVersion) || incompatibleVersions(jsonprovider.FormatVersion, plan.ProviderFormatVersion) {
|
||||
renderer.Streams.Println(format.WordWrap(
|
||||
renderer.Colorize.Color("\n[bold][red]Warning:[reset][bold] This plan was generated using a different version of Terraform, the diff presented here may be missing representations of recent features."),
|
||||
|
||||
Reference in New Issue
Block a user