Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend/remote: No version check for operations #27319

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions backend/remote/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions backend/remote/backend_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down