From 718fa3895f7364f75d0418595f15a31bb7b99ef7 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 14 Sep 2021 09:43:00 -0700 Subject: [PATCH] backend: Remove Operation.Parallelism field The presence of this field was confusing because in practice the local backend doesn't use it for anything and the remote backend was using it only to return an error if it's set to anything other than the default, under the assumption that it would always match ContextOpts.Parallelism. The "command" package is the one actually responsible for handling this option, and it does so by placing it into the partial ContextOpts which it passes into the backend when preparing for a local operation. To make that clearer, here we remove Operation.Parallelism and change the few uses of it to refer to ContextOpts.Parallelism instead, so that everyone is reading and writing this value from the same place. --- internal/backend/backend.go | 1 - internal/backend/remote/backend_apply.go | 2 +- internal/backend/remote/backend_apply_test.go | 6 ++++-- internal/backend/remote/backend_plan.go | 2 +- internal/backend/remote/backend_plan_test.go | 6 ++++-- internal/command/meta_backend.go | 1 - 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/backend/backend.go b/internal/backend/backend.go index caac42cc67..d8b28b9435 100644 --- a/internal/backend/backend.go +++ b/internal/backend/backend.go @@ -249,7 +249,6 @@ type Operation struct { // behavior of the operation. PlanMode plans.Mode AutoApprove bool - Parallelism int Targets []addrs.Targetable ForceReplace []addrs.AbsResourceInstance Variables map[string]UnparsedVariableValue diff --git a/internal/backend/remote/backend_apply.go b/internal/backend/remote/backend_apply.go index 2ec123d30a..ef89466a23 100644 --- a/internal/backend/remote/backend_apply.go +++ b/internal/backend/remote/backend_apply.go @@ -42,7 +42,7 @@ func (b *Remote) opApply(stopCtx, cancelCtx context.Context, op *backend.Operati return nil, diags.Err() } - if op.Parallelism != defaultParallelism { + if b.ContextOpts != nil && b.ContextOpts.Parallelism != defaultParallelism { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, "Custom parallelism values are currently not supported", diff --git a/internal/backend/remote/backend_apply_test.go b/internal/backend/remote/backend_apply_test.go index d549145597..4bc2a909f2 100644 --- a/internal/backend/remote/backend_apply_test.go +++ b/internal/backend/remote/backend_apply_test.go @@ -46,7 +46,6 @@ func testOperationApplyWithTimeout(t *testing.T, configDir string, timeout time. return &backend.Operation{ ConfigDir: configDir, ConfigLoader: configLoader, - Parallelism: defaultParallelism, PlanRefresh: true, StateLocker: clistate.NewLocker(timeout, stateLockerView), Type: backend.OperationTypeApply, @@ -223,7 +222,10 @@ func TestRemote_applyWithParallelism(t *testing.T) { op, configCleanup, done := testOperationApply(t, "./testdata/apply") defer configCleanup() - op.Parallelism = 3 + if b.ContextOpts == nil { + b.ContextOpts = &terraform.ContextOpts{} + } + b.ContextOpts.Parallelism = 3 op.Workspace = backend.DefaultStateName run, err := b.Operation(context.Background(), op) diff --git a/internal/backend/remote/backend_plan.go b/internal/backend/remote/backend_plan.go index 82f33ec2dc..736c040b4d 100644 --- a/internal/backend/remote/backend_plan.go +++ b/internal/backend/remote/backend_plan.go @@ -38,7 +38,7 @@ func (b *Remote) opPlan(stopCtx, cancelCtx context.Context, op *backend.Operatio return nil, diags.Err() } - if op.Parallelism != defaultParallelism { + if b.ContextOpts != nil && b.ContextOpts.Parallelism != defaultParallelism { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, "Custom parallelism values are currently not supported", diff --git a/internal/backend/remote/backend_plan_test.go b/internal/backend/remote/backend_plan_test.go index a231f149ec..6d4ced7b87 100644 --- a/internal/backend/remote/backend_plan_test.go +++ b/internal/backend/remote/backend_plan_test.go @@ -44,7 +44,6 @@ func testOperationPlanWithTimeout(t *testing.T, configDir string, timeout time.D return &backend.Operation{ ConfigDir: configDir, ConfigLoader: configLoader, - Parallelism: defaultParallelism, PlanRefresh: true, StateLocker: clistate.NewLocker(timeout, stateLockerView), Type: backend.OperationTypePlan, @@ -198,7 +197,10 @@ func TestRemote_planWithParallelism(t *testing.T) { op, configCleanup, done := testOperationPlan(t, "./testdata/plan") defer configCleanup() - op.Parallelism = 3 + if b.ContextOpts == nil { + b.ContextOpts = &terraform.ContextOpts{} + } + b.ContextOpts.Parallelism = 3 op.Workspace = backend.DefaultStateName run, err := b.Operation(context.Background(), op) diff --git a/internal/command/meta_backend.go b/internal/command/meta_backend.go index 71ebfbe262..82ecd89c78 100644 --- a/internal/command/meta_backend.go +++ b/internal/command/meta_backend.go @@ -349,7 +349,6 @@ func (m *Meta) Operation(b backend.Backend) *backend.Operation { return &backend.Operation{ PlanOutBackend: planOutBackend, - Parallelism: m.parallelism, Targets: m.targets, UIIn: m.UIInput(), UIOut: m.Ui,