Merge pull request #28093 from hashicorp/alisdair/fix-new-remote-workspace-state-migration

backend/remote: Fix new workspace state migration
This commit is contained in:
Alisdair McDiarmid 2021-03-16 09:32:49 -04:00 committed by GitHub
commit d4e7a74f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -854,6 +854,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",

View File

@ -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")
}