From 69e7922a33022c3cba0a2fc0232d1d116a3fc484 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Fri, 16 Apr 2021 09:57:04 -0400 Subject: [PATCH 1/2] cli: Fix missing apply summary for remote runs Disabling the resource count and outputs rendering when the remote backend is in use causes them to be omitted from Terraform Cloud runs. This commit changes the condition to render these values if either the remote backend is not in use, or the command is running in automation via the TF_IN_AUTOMATION flag. As this is intended to be set by Terraform Cloud and other remote backend implementations, this addresses the problem. --- command/apply.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/apply.go b/command/apply.go index 6365917d4..c5f7180dd 100644 --- a/command/apply.go +++ b/command/apply.go @@ -123,8 +123,8 @@ func (c *ApplyCommand) Run(rawArgs []string) int { } // Render the resource count and outputs, unless we're using the remote - // backend, in which case these are rendered remotely - if _, isRemoteBackend := be.(*remoteBackend.Remote); !isRemoteBackend { + // backend locally, in which case these are rendered remotely + if _, isRemoteBackend := be.(*remoteBackend.Remote); !isRemoteBackend || c.RunningInAutomation { view.ResourceCount(args.State.StateOutPath) if !c.Destroy && op.State != nil { view.Outputs(op.State.RootModule().OutputValues) From 8dcf768f4ec182e6c5366572ce447fc5a2ea45cf Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Fri, 16 Apr 2021 11:43:57 -0400 Subject: [PATCH 2/2] backend/remote: Add IsLocalOperations To ensure that the apply command can determine whether an operation is executed locally or remotely, we add an IsLocalOperations method on the remote backend. This returns the internal forceLocal boolean. We also update this flag after checking if the corresponding remote workspace is in local operations mode or not. This ensures that we know if an operation is running locally (entirely on the practitioner's machine), pseudo-locally (on a Terraform Cloud worker), or remotely (executing on a worker, rendering locally). --- backend/remote/backend.go | 7 +++++++ command/apply.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/remote/backend.go b/backend/remote/backend.go index 28f9d95c4..43eb77fbc 100644 --- a/backend/remote/backend.go +++ b/backend/remote/backend.go @@ -704,6 +704,9 @@ func (b *Remote) Operation(ctx context.Context, op *backend.Operation) (*backend // Check if we need to use the local backend to run the operation. if b.forceLocal || !w.Operations { + // Record that we're forced to run operations locally to allow the + // command package UI to operate correctly + b.forceLocal = true return b.local.Operation(ctx, op) } @@ -949,6 +952,10 @@ func (b *Remote) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.D return diags } +func (b *Remote) IsLocalOperations() bool { + return b.forceLocal +} + // Colorize returns the Colorize structure that can be used for colorizing // output. This is guaranteed to always return a non-nil value and so useful // as a helper to wrap any potentially colored strings. diff --git a/command/apply.go b/command/apply.go index c5f7180dd..178cfbebe 100644 --- a/command/apply.go +++ b/command/apply.go @@ -124,7 +124,7 @@ func (c *ApplyCommand) Run(rawArgs []string) int { // Render the resource count and outputs, unless we're using the remote // backend locally, in which case these are rendered remotely - if _, isRemoteBackend := be.(*remoteBackend.Remote); !isRemoteBackend || c.RunningInAutomation { + if rb, isRemoteBackend := be.(*remoteBackend.Remote); !isRemoteBackend || rb.IsLocalOperations() { view.ResourceCount(args.State.StateOutPath) if !c.Destroy && op.State != nil { view.Outputs(op.State.RootModule().OutputValues)