cli: Fix remote backend UI issues

Fix two bugs which surface when using the remote backend:

- When migrating to views, we removed the call to `(*Meta).process`
  which initialized the color boolean. This resulted in the legacy UI
  calls in the remote backend stripping color codes. To fix this, we
  populate this boolean from the common arguments.
- Remote apply will output the resource summary and output changes, and
  these are rendered via the remote backend streaming. We need to
  special case this in the apply command and prevent displaying a
  zero-change summary line.

Neither of these are coverable by automated tests, as we don't have any
command-package level testing for the remote backend. Manually verified.
This commit is contained in:
Alisdair McDiarmid 2021-04-16 08:28:33 -04:00
parent dedac2cdd6
commit fad305f884
2 changed files with 18 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
"strings" "strings"
"github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/backend"
remoteBackend "github.com/hashicorp/terraform/backend/remote"
"github.com/hashicorp/terraform/command/arguments" "github.com/hashicorp/terraform/command/arguments"
"github.com/hashicorp/terraform/command/views" "github.com/hashicorp/terraform/command/views"
"github.com/hashicorp/terraform/plans/planfile" "github.com/hashicorp/terraform/plans/planfile"
@ -26,6 +27,11 @@ func (c *ApplyCommand) Run(rawArgs []string) int {
common, rawArgs := arguments.ParseView(rawArgs) common, rawArgs := arguments.ParseView(rawArgs)
c.View.Configure(common) c.View.Configure(common)
// Propagate -no-color for the remote backend's legacy use of Ui. This
// should be removed when the remote backend is migrated to views.
c.Meta.color = !common.NoColor
c.Meta.Color = c.Meta.color
// Parse and validate flags // Parse and validate flags
args, diags := arguments.ParseApply(rawArgs) args, diags := arguments.ParseApply(rawArgs)
@ -116,10 +122,13 @@ func (c *ApplyCommand) Run(rawArgs []string) int {
return op.Result.ExitStatus() return op.Result.ExitStatus()
} }
// // Render the resource count and outputs // Render the resource count and outputs, unless we're using the remote
view.ResourceCount(args.State.StateOutPath) // backend, in which case these are rendered remotely
if !c.Destroy && op.State != nil { if _, isRemoteBackend := be.(*remoteBackend.Remote); !isRemoteBackend {
view.Outputs(op.State.RootModule().OutputValues) view.ResourceCount(args.State.StateOutPath)
if !c.Destroy && op.State != nil {
view.Outputs(op.State.RootModule().OutputValues)
}
} }
view.Diagnostics(diags) view.Diagnostics(diags)

View File

@ -21,6 +21,11 @@ func (c *PlanCommand) Run(rawArgs []string) int {
common, rawArgs := arguments.ParseView(rawArgs) common, rawArgs := arguments.ParseView(rawArgs)
c.View.Configure(common) c.View.Configure(common)
// Propagate -no-color for the remote backend's legacy use of Ui. This
// should be removed when the remote backend is migrated to views.
c.Meta.color = !common.NoColor
c.Meta.Color = c.Meta.color
// Parse and validate flags // Parse and validate flags
args, diags := arguments.ParsePlan(rawArgs) args, diags := arguments.ParsePlan(rawArgs)