Skip to content

Commit

Permalink
resource/aws_workspaces_workspace: Fix Terminated Workspace Panic (#1…
Browse files Browse the repository at this point in the history
…6692)

Output from acceptance testing:

```
--- PASS: TestFlattenWorkspaceProperties (0.00s)
--- PASS: TestExpandWorkspaceProperties (0.00s)
--- PASS: TestAccAwsWorkspacesWorkspace_validateRootVolumeSize (3.40s)
--- PASS: TestAccAwsWorkspacesWorkspace_validateUserVolumeSize (3.96s)
--- PASS: TestAccAwsWorkspacesWorkspace_workspaceProperties_runningModeAlwaysOn (1775.72s)
--- PASS: TestAccAwsWorkspacesWorkspace_recreate (1836.44s)
--- PASS: TestAccAwsWorkspacesWorkspace_timeout (1848.37s)
--- PASS: TestAccAwsWorkspacesWorkspace_basic (1852.09s)
--- PASS: TestAccAwsWorkspacesWorkspace_tags (1876.63s)
--- PASS: TestAccAwsWorkspacesWorkspace_workspaceProperties (1899.23s)
```
  • Loading branch information
Tensho authored Dec 15, 2020
1 parent 5a8571c commit 402132b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 37 deletions.
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
}

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"
}
}
`
`, 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

0 comments on commit 402132b

Please sign in to comment.