Skip to content

Commit

Permalink
Merge pull request #15705 from Tensho/fix-workspace-termintation
Browse files Browse the repository at this point in the history
Consider Workspace State Fully Terminated Only After Directory Metadata Cleanup
  • Loading branch information
breathingdust authored Oct 22, 2020
2 parents 31a3e4d + d64a811 commit ff209be
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
9 changes: 8 additions & 1 deletion aws/internal/service/workspaces/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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,
}
Expand Down
35 changes: 34 additions & 1 deletion aws/resource_aws_workspaces_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]

Expand Down

0 comments on commit ff209be

Please sign in to comment.