Succeed cloud workspace deletion if the workspace does not exist

This commit is contained in:
Jarrett Spiker
2022-10-11 12:31:25 -04:00
parent 1dafd7c0b1
commit c16d726f2c
2 changed files with 6 additions and 5 deletions

View File

@@ -526,6 +526,10 @@ func (b *Cloud) DeleteWorkspace(name string, force bool) error {
}
workspace, err := b.client.Workspaces.Read(context.Background(), b.organization, name)
if err == tfe.ErrResourceNotFound {
return nil // If the workspace does not exist, succeed
}
if err != nil {
return fmt.Errorf("failed to retrieve workspace %s: %v", name, err)
}

View File

@@ -1211,10 +1211,7 @@ func TestClodBackend_DeleteWorkspace_DoesNotExist(t *testing.T) {
defer bCleanup()
err := b.DeleteWorkspace("non-existent-workspace", false)
if err == nil {
t.Fatalf("expected deleting a workspace which does not exist to fail")
}
if !strings.Contains(err.Error(), "failed to retrieve workspace non-existent-workspace") {
t.Fatalf("expected deletion to fail with cannot find workspace error, but got %s", err.Error())
if err != nil {
t.Fatalf("expected deleting a workspace which does not exist to succeed")
}
}