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/views: Remove baseState argument from plan-rendering views #28656

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/local/backend_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (b *Local) opApply(
}

if !trivialPlan {
op.View.Plan(plan, runningOp.State, tfCtx.Schemas())
op.View.Plan(plan, tfCtx.Schemas())
}

// We'll show any accumulated warnings before we display the prompt,
Expand Down
2 changes: 1 addition & 1 deletion backend/local/backend_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (b *Local) opPlan(
}

// Render the plan
op.View.Plan(plan, plan.PriorState, tfCtx.Schemas())
op.View.Plan(plan, tfCtx.Schemas())

// If we've accumulated any warnings along the way then we'll show them
// here just before we show the summary and next steps. If we encountered
Expand Down
2 changes: 1 addition & 1 deletion command/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (c *ShowCommand) Run(args []string) int {
}

view := views.NewShow(arguments.ViewHuman, c.View)
view.Plan(plan, stateFile.State, schemas)
view.Plan(plan, schemas)
return 0
}

Expand Down
9 changes: 4 additions & 5 deletions command/views/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/hashicorp/terraform/command/format"
"github.com/hashicorp/terraform/command/views/json"
"github.com/hashicorp/terraform/plans"
"github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/states/statefile"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform/tfdiags"
Expand All @@ -26,7 +25,7 @@ type Operation interface {

PlannedChange(change *plans.ResourceInstanceChangeSrc)
PlanNoChanges()
Plan(plan *plans.Plan, baseState *states.State, schemas *terraform.Schemas)
Plan(plan *plans.Plan, schemas *terraform.Schemas)
PlanNextStep(planPath string)

Diagnostics(diags tfdiags.Diagnostics)
Expand Down Expand Up @@ -92,8 +91,8 @@ func (v *OperationHuman) PlanNoChanges() {
v.view.streams.Println("\n" + strings.TrimSpace(format.WordWrap(planNoChangesDetail, v.view.outputColumns())))
}

func (v *OperationHuman) Plan(plan *plans.Plan, baseState *states.State, schemas *terraform.Schemas) {
renderPlan(plan, baseState, schemas, v.view)
func (v *OperationHuman) Plan(plan *plans.Plan, schemas *terraform.Schemas) {
renderPlan(plan, schemas, v.view)
}

func (v *OperationHuman) PlannedChange(change *plans.ResourceInstanceChangeSrc) {
Expand Down Expand Up @@ -172,7 +171,7 @@ func (v *OperationJSON) PlanNoChanges() {

// Log a change summary and a series of "planned" messages for the changes in
// the plan.
func (v *OperationJSON) Plan(plan *plans.Plan, baseState *states.State, schemas *terraform.Schemas) {
func (v *OperationJSON) Plan(plan *plans.Plan, schemas *terraform.Schemas) {
cs := &json.ChangeSummary{
Operation: json.OperationPlanned,
}
Expand Down
6 changes: 2 additions & 4 deletions command/views/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/hashicorp/terraform/command/arguments"
"github.com/hashicorp/terraform/internal/terminal"
"github.com/hashicorp/terraform/plans"
"github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/states/statefile"
)

Expand Down Expand Up @@ -88,9 +87,8 @@ func TestOperation_plan(t *testing.T) {
v := NewOperation(arguments.ViewHuman, true, NewView(streams))

plan := testPlan(t)
state := states.NewState()
schemas := testSchemas()
v.Plan(plan, state, schemas)
v.Plan(plan, schemas)

want := `
Terraform used the selected providers to generate the following execution
Expand Down Expand Up @@ -308,7 +306,7 @@ func TestOperationJSON_plan(t *testing.T) {
},
},
}
v.Plan(plan, nil, nil)
v.Plan(plan, nil)

want := []map[string]interface{}{
// Create-then-delete should result in replace
Expand Down
3 changes: 1 addition & 2 deletions command/views/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/hashicorp/terraform/command/arguments"
"github.com/hashicorp/terraform/command/format"
"github.com/hashicorp/terraform/plans"
"github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform/tfdiags"
)
Expand Down Expand Up @@ -96,7 +95,7 @@ func (v *PlanJSON) HelpPrompt() {

// The plan renderer is used by the Operation view (for plan and apply
// commands) and the Show view (for the show command).
func renderPlan(plan *plans.Plan, baseState *states.State, schemas *terraform.Schemas, view *View) {
func renderPlan(plan *plans.Plan, schemas *terraform.Schemas, view *View) {
counts := map[plans.Action]int{}
var rChanges []*plans.ResourceInstanceChangeSrc
for _, change := range plan.Changes.Resources {
Expand Down
7 changes: 3 additions & 4 deletions command/views/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import (

"github.com/hashicorp/terraform/command/arguments"
"github.com/hashicorp/terraform/plans"
"github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/terraform"
)

// FIXME: this is a temporary partial definition of the view for the show
// command, in place to allow access to the plan renderer which is now in the
// views package.
type Show interface {
Plan(plan *plans.Plan, baseState *states.State, schemas *terraform.Schemas)
Plan(plan *plans.Plan, schemas *terraform.Schemas)
}

// FIXME: the show view should support both human and JSON types. This code is
Expand All @@ -34,6 +33,6 @@ type ShowHuman struct {

var _ Show = (*ShowHuman)(nil)

func (v *ShowHuman) Plan(plan *plans.Plan, baseState *states.State, schemas *terraform.Schemas) {
renderPlan(plan, baseState, schemas, &v.View)
func (v *ShowHuman) Plan(plan *plans.Plan, schemas *terraform.Schemas) {
renderPlan(plan, schemas, &v.View)
}