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).
This commit is contained in:
parent
69e7922a33
commit
8dcf768f4e
|
@ -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.
|
// Check if we need to use the local backend to run the operation.
|
||||||
if b.forceLocal || !w.Operations {
|
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)
|
return b.local.Operation(ctx, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -949,6 +952,10 @@ func (b *Remote) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.D
|
||||||
return diags
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Remote) IsLocalOperations() bool {
|
||||||
|
return b.forceLocal
|
||||||
|
}
|
||||||
|
|
||||||
// Colorize returns the Colorize structure that can be used for colorizing
|
// 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
|
// output. This is guaranteed to always return a non-nil value and so useful
|
||||||
// as a helper to wrap any potentially colored strings.
|
// as a helper to wrap any potentially colored strings.
|
||||||
|
|
|
@ -124,7 +124,7 @@ func (c *ApplyCommand) Run(rawArgs []string) int {
|
||||||
|
|
||||||
// Render the resource count and outputs, unless we're using the remote
|
// Render the resource count and outputs, unless we're using the remote
|
||||||
// backend locally, in which case these are rendered remotely
|
// 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)
|
view.ResourceCount(args.State.StateOutPath)
|
||||||
if !c.Destroy && op.State != nil {
|
if !c.Destroy && op.State != nil {
|
||||||
view.Outputs(op.State.RootModule().OutputValues)
|
view.Outputs(op.State.RootModule().OutputValues)
|
||||||
|
|
Loading…
Reference in New Issue