From 619c6727ef5bfb3c3c6cd056aafe9dc0b7f484a7 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Thu, 17 Dec 2020 12:56:13 -0500 Subject: [PATCH] backend/remote: No version check for operations Terraform remote version conflicts are not a concern for operations. We are in one of three states: - Running remotely, in which case the local version is irrelevant; - Workspace configured for local operations, in which case the remote version is meaningless; - Forcing local operations with a remote backend, which should only happen in the Terraform Cloud worker, in which case the Terraform versions by definition match. This commit therefore disables the version check for operations (plan and apply), which has the consequence of disabling it in Terraform Cloud and Enterprise runs. In turn this enables Terraform Enterprise runs with bundles which have a version that doesn't exactly match the bundled Terraform version. --- backend/remote/backend.go | 19 +++++++++++-------- backend/remote/backend_apply_test.go | 5 ++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/backend/remote/backend.go b/backend/remote/backend.go index 3e9173e40..8ff64e34a 100644 --- a/backend/remote/backend.go +++ b/backend/remote/backend.go @@ -694,19 +694,22 @@ func (b *Remote) Operation(ctx context.Context, op *backend.Operation) (*backend } } + // Terraform remote version conflicts are not a concern for operations. We + // are in one of three states: + // + // - Running remotely, in which case the local version is irrelevant; + // - Workspace configured for local operations, in which case the remote + // version is meaningless; + // - Forcing local operations with a remote backend, which should only + // happen in the Terraform Cloud worker, in which case the Terraform + // versions by definition match. + b.IgnoreVersionConflict() + // Check if we need to use the local backend to run the operation. if b.forceLocal || !w.Operations { - if !w.Operations { - // Workspace is explicitly configured for local operations, so its - // configured Terraform version is meaningless - b.IgnoreVersionConflict() - } return b.local.Operation(ctx, op) } - // Running remotely so we don't care about version conflicts - b.IgnoreVersionConflict() - // Set the remote workspace name. op.Workspace = w.Name diff --git a/backend/remote/backend_apply_test.go b/backend/remote/backend_apply_test.go index 40262aab7..cc933b4af 100644 --- a/backend/remote/backend_apply_test.go +++ b/backend/remote/backend_apply_test.go @@ -1298,12 +1298,11 @@ func TestRemote_applyVersionCheck(t *testing.T) { remoteVersion: "0.13.5", hasOperations: false, }, - "error if force local, has remote operations, different versions": { + "force local with remote operations and different versions is acceptable": { localVersion: "0.14.0", - remoteVersion: "0.13.5", + remoteVersion: "0.14.0-acme-provider-bundle", forceLocal: true, hasOperations: true, - wantErr: `Remote workspace Terraform version "0.13.5" does not match local Terraform version "0.14.0"`, }, "no error if versions are identical": { localVersion: "0.14.0",