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

Fix Terminated Workspace Panic #16692

Merged
merged 4 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion aws/internal/service/workspaces/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func WorkspaceState(conn *workspaces.WorkSpaces, workspaceID string) resource.St
}

if len(output.Workspaces) == 0 {
return nil, "", nil
return output, workspaces.WorkspaceStateTerminated, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We consider an empty list in output as a real workspace termination sign. The workspaces.WorkspaceStateTerminated state is checked right after the DescriobeWorkspaces call in Read func.

}

workspace := output.Workspaces[0]
Expand Down
2 changes: 1 addition & 1 deletion aws/internal/service/workspaces/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func WorkspaceTerminated(conn *workspaces.WorkSpaces, workspaceID string, timeou
workspaces.WorkspaceStateTerminating,
workspaces.WorkspaceStateError,
},
Target: []string{},
Target: []string{workspaces.WorkspaceStateTerminated},
Refresh: WorkspaceState(conn, workspaceID),
Timeout: timeout,
}
Expand Down
107 changes: 72 additions & 35 deletions aws/resource_aws_workspaces_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func TestAccAwsWorkspacesWorkspace_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.running_mode", workspaces.RunningModeAlwaysOn),
resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.running_mode_auto_stop_timeout_in_minutes", "0"),
resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.user_volume_size_gib", "10"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.Name", fmt.Sprintf("tf-testacc-workspaces-workspace-%[1]s", rName)),
),
},
{
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestAccAwsWorkspacesWorkspace_tags(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsWorkspacesWorkspaceExists(resourceName, &v1),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.TerraformProviderAwsTest", "true"),
resource.TestCheckResourceAttr(resourceName, "tags.Name", fmt.Sprintf("tf-testacc-workspaces-workspace-%[1]s", rName)),
resource.TestCheckResourceAttr(resourceName, "tags.Alpha", "1"),
),
},
Expand All @@ -136,7 +137,7 @@ func TestAccAwsWorkspacesWorkspace_tags(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsWorkspacesWorkspaceExists(resourceName, &v2),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.TerraformProviderAwsTest", "true"),
resource.TestCheckResourceAttr(resourceName, "tags.Name", fmt.Sprintf("tf-testacc-workspaces-workspace-%[1]s", rName)),
resource.TestCheckResourceAttr(resourceName, "tags.Beta", "2"),
),
},
Expand All @@ -145,7 +146,7 @@ func TestAccAwsWorkspacesWorkspace_tags(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsWorkspacesWorkspaceExists(resourceName, &v3),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.TerraformProviderAwsTest", "true"),
resource.TestCheckResourceAttr(resourceName, "tags.Name", fmt.Sprintf("tf-testacc-workspaces-workspace-%[1]s", rName)),
),
},
},
Expand Down Expand Up @@ -401,32 +402,44 @@ func testAccCheckAwsWorkspacesWorkspaceExists(n string, v *workspaces.Workspace)
func testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName string) string {
return composeConfig(
testAccAwsWorkspacesDirectoryConfig_Prerequisites(rName),
`
fmt.Sprintf(`
data "aws_workspaces_bundle" "test" {
bundle_id = "wsb-bh8rsxt14" # Value with Windows 10 (English)
}

resource "aws_workspaces_directory" "test" {
directory_id = aws_directory_service_directory.main.id

tags = {
Name = "tf-testacc-workspaces-directory-%[1]s"
}
}
`)
`, rName))
}

func testAccWorkspacesWorkspaceConfig(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id

# NOTE: WorkSpaces API doesn't allow creating users in the directory.
# However, "Administrator"" user is always present in a bare directory.
user_name = "Administrator"

tags = {
Name = "tf-testacc-workspaces-workspace-%[1]s"
}
Tensho marked this conversation as resolved.
Show resolved Hide resolved
}
`
`, rName))
}

func testAccWorkspacesWorkspaceConfig_TagsA(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id
Expand All @@ -436,15 +449,17 @@ resource "aws_workspaces_workspace" "test" {
user_name = "Administrator"

tags = {
TerraformProviderAwsTest = true
Alpha = 1
Name = "tf-testacc-workspaces-workspace-%[1]s"
Alpha = 1
}
}
`
`, rName))
}

func testAccWorkspacesWorkspaceConfig_TagsB(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id
Expand All @@ -454,15 +469,17 @@ resource "aws_workspaces_workspace" "test" {
user_name = "Administrator"

tags = {
TerraformProviderAwsTest = true
Beta = 2
Name = "tf-testacc-workspaces-workspace-%[1]s"
Beta = 2
}
}
`
`, rName))
}

func testAccWorkspacesWorkspaceConfig_TagsC(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id
Expand All @@ -472,14 +489,16 @@ resource "aws_workspaces_workspace" "test" {
user_name = "Administrator"

tags = {
TerraformProviderAwsTest = true
Name = "tf-testacc-workspaces-workspace-%[1]s"
}
}
`
`, rName))
}

func testAccWorkspacesWorkspaceConfig_WorkspacePropertiesA(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id
Expand All @@ -495,14 +514,16 @@ resource "aws_workspaces_workspace" "test" {
}

tags = {
TerraformProviderAwsTest = true
Name = "tf-testacc-workspaces-workspace-%[1]s"
}
}
`
`, rName))
}

func testAccWorkspacesWorkspaceConfig_WorkspacePropertiesB(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id
Expand All @@ -517,14 +538,16 @@ resource "aws_workspaces_workspace" "test" {
}

tags = {
TerraformProviderAwsTest = true
Name = "tf-testacc-workspaces-workspace-%[1]s"
}
}
`
`, rName))
}

func testAccWorkspacesWorkspaceConfig_WorkspacePropertiesC(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id
Expand All @@ -535,12 +558,18 @@ resource "aws_workspaces_workspace" "test" {

workspace_properties {
}

tags = {
Name = "tf-testacc-workspaces-workspace-%[1]s"
}
}
`
`, rName))
}

func testAccWorkspacesWorkspaceConfig_validateRootVolumeSize(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id
Expand All @@ -555,14 +584,16 @@ resource "aws_workspaces_workspace" "test" {
}

tags = {
TerraformProviderAwsTest = true
Name = "tf-testacc-workspaces-workspace-%[1]s"
}
}
`
`, rName))
}

func testAccWorkspacesWorkspaceConfig_validateUserVolumeSize(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id
Expand All @@ -577,14 +608,16 @@ resource "aws_workspaces_workspace" "test" {
}

tags = {
TerraformProviderAwsTest = true
Name = "tf-testacc-workspaces-workspace-%[1]s"
}
}
`
`, rName))
}

func testAccWorkspacesWorkspaceConfig_timeout(rName string) string {
return testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName) + `
return composeConfig(
testAccAwsWorkspacesWorkspaceConfig_Prerequisites(rName),
fmt.Sprintf(`
resource "aws_workspaces_workspace" "test" {
bundle_id = data.aws_workspaces_bundle.test.id
directory_id = aws_workspaces_directory.test.id
Expand All @@ -598,8 +631,12 @@ resource "aws_workspaces_workspace" "test" {
update = "30m"
delete = "30m"
}

tags = {
Name = "tf-testacc-workspaces-workspace-%[1]s"
}
}
`
`, rName))
}

func TestExpandWorkspaceProperties(t *testing.T) {
Expand Down