From beb1f7413cdd4ebdccecc3e77a4484f3499832c6 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Mon, 15 Mar 2021 19:40:51 +0000 Subject: [PATCH] backport of commit 4b159416ff38c89283f571f002922ba95b8eda4e --- backend/remote/backend.go | 7 +++++++ backend/remote/backend_test.go | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/remote/backend.go b/backend/remote/backend.go index c79ff32e8c..b14bb2d250 100644 --- a/backend/remote/backend.go +++ b/backend/remote/backend.go @@ -888,6 +888,13 @@ func (b *Remote) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.D workspace, err := b.getRemoteWorkspace(context.Background(), workspaceName) if err != nil { + // If the workspace doesn't exist, there can be no compatibility + // problem, so we can return. This is most likely to happen when + // migrating state from a local backend to a new workspace. + if err == tfe.ErrResourceNotFound { + return nil + } + diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, "Error looking up workspace", diff --git a/backend/remote/backend_test.go b/backend/remote/backend_test.go index 0155ba590c..051d564104 100644 --- a/backend/remote/backend_test.go +++ b/backend/remote/backend_test.go @@ -629,8 +629,15 @@ func TestRemote_VerifyWorkspaceTerraformVersion_workspaceErrors(t *testing.T) { defer bCleanup() // Attempting to check the version against a workspace which doesn't exist - // should fail + // should result in no errors diags := b.VerifyWorkspaceTerraformVersion("invalid-workspace") + if len(diags) != 0 { + t.Fatalf("unexpected error: %s", diags.Err()) + } + + // Use a special workspace ID to trigger a 500 error, which should result + // in a failed check + diags = b.VerifyWorkspaceTerraformVersion("network-error") if len(diags) != 1 { t.Fatal("expected diag, but none returned") }