Merge pull request #27407 from hashicorp/alisdair/backend-disable-version-check-for-workspaces-with-local-operations

backend/remote: No version check for local ops
This commit is contained in:
Alisdair McDiarmid 2021-01-05 13:53:59 -05:00 committed by GitHub
commit afbde358fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

View File

@ -903,6 +903,12 @@ func (b *Remote) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.D
return nil return nil
} }
// If the workspace has remote operations disabled, the remote Terraform
// version is effectively meaningless, so we'll skip version verification.
if workspace.Operations == false {
return nil
}
remoteVersion, err := version.NewSemver(workspace.TerraformVersion) remoteVersion, err := version.NewSemver(workspace.TerraformVersion)
if err != nil { if err != nil {
diags = diags.Append(tfdiags.Sourceless( diags = diags.Append(tfdiags.Sourceless(

View File

@ -556,18 +556,20 @@ func TestRemote_StateMgr_versionCheckLatest(t *testing.T) {
func TestRemote_VerifyWorkspaceTerraformVersion(t *testing.T) { func TestRemote_VerifyWorkspaceTerraformVersion(t *testing.T) {
testCases := []struct { testCases := []struct {
local string local string
remote string remote string
wantErr bool operations bool
wantErr bool
}{ }{
{"0.13.5", "0.13.5", false}, {"0.13.5", "0.13.5", true, false},
{"0.14.0", "0.13.5", true}, {"0.14.0", "0.13.5", true, true},
{"0.14.0", "0.14.1", false}, {"0.14.0", "0.13.5", false, false},
{"0.14.0", "1.0.99", false}, {"0.14.0", "0.14.1", true, false},
{"0.14.0", "1.1.0", true}, {"0.14.0", "1.0.99", true, false},
{"1.2.0", "1.2.99", false}, {"0.14.0", "1.1.0", true, true},
{"1.2.0", "1.3.0", true}, {"1.2.0", "1.2.99", true, false},
{"0.15.0", "latest", false}, {"1.2.0", "1.3.0", true, true},
{"0.15.0", "latest", true, false},
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("local %s, remote %s", tc.local, tc.remote), func(t *testing.T) { t.Run(fmt.Sprintf("local %s, remote %s", tc.local, tc.remote), func(t *testing.T) {
@ -598,6 +600,7 @@ func TestRemote_VerifyWorkspaceTerraformVersion(t *testing.T) {
b.organization, b.organization,
b.workspace, b.workspace,
tfe.WorkspaceUpdateOptions{ tfe.WorkspaceUpdateOptions{
Operations: tfe.Bool(tc.operations),
TerraformVersion: tfe.String(tc.remote), TerraformVersion: tfe.String(tc.remote),
}, },
); err != nil { ); err != nil {