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

Consider Workspace State Fully Terminated Only After Directory Metadata Cleanup #15705

Merged
merged 1 commit into from
Oct 22, 2020
Merged
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
9 changes: 8 additions & 1 deletion aws/internal/service/workspaces/waiter/status.go
Original file line number Diff line number Diff line change
@@ -34,10 +34,17 @@ func WorkspaceState(conn *workspaces.WorkSpaces, workspaceID string) resource.St
}

if len(output.Workspaces) == 0 {
return nil, workspaces.WorkspaceStateTerminated, nil
return nil, "", nil
}

workspace := output.Workspaces[0]

// https://docs.aws.amazon.com/workspaces/latest/api/API_TerminateWorkspaces.html
// State TERMINATED is overridden with TERMINATING to catch up directory metadata clean up.
if aws.StringValue(workspace.State) == workspaces.WorkspaceStateTerminated {
return workspace, workspaces.WorkspaceStateTerminating, nil
}

return workspace, aws.StringValue(workspace.State), nil
}
}
4 changes: 1 addition & 3 deletions aws/internal/service/workspaces/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -109,9 +109,7 @@ func WorkspaceTerminated(conn *workspaces.WorkSpaces, workspaceID string) (*work
workspaces.WorkspaceStateTerminating,
workspaces.WorkspaceStateError,
},
Target: []string{
workspaces.WorkspaceStateTerminated,
},
Target: []string{},
Refresh: WorkspaceState(conn, workspaceID),
Timeout: WorkspaceTerminatedTimeout,
}
35 changes: 34 additions & 1 deletion aws/resource_aws_workspaces_workspace_test.go
Original file line number Diff line number Diff line change
@@ -284,6 +284,39 @@ func TestAccAwsWorkspacesWorkspace_validateUserVolumeSize(t *testing.T) {
})
}

func TestAccAwsWorkspacesWorkspace_recreate(t *testing.T) {
var v workspaces.Workspace
rName := acctest.RandString(8)

resourceName := "aws_workspaces_workspace.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWorkspacesDirectory(t)
testAccPreCheckAWSDirectoryServiceSimpleDirectory(t)
testAccPreCheckHasIAMRole(t, "workspaces_DefaultRole")
},
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsWorkspacesWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccWorkspacesWorkspaceConfig(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsWorkspacesWorkspaceExists(resourceName, &v),
),
},
{
Taint: []string{resourceName}, // Force workspace re-creation
Config: testAccWorkspacesWorkspaceConfig(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsWorkspacesWorkspaceExists(resourceName, &v),
),
},
},
})
}

func testAccCheckAwsWorkspacesWorkspaceDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).workspacesconn

@@ -300,7 +333,7 @@ func testAccCheckAwsWorkspacesWorkspaceDestroy(s *terraform.State) error {
}

if len(resp.Workspaces) == 0 {
return fmt.Errorf("workspace %q was not terminated", rs.Primary.ID)
return nil
}
ws := resp.Workspaces[0]