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

AWS Workspaces fix for issue 13558 #13976

Merged
merged 3 commits into from
Sep 1, 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
17 changes: 11 additions & 6 deletions aws/resource_aws_workspaces_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,18 @@ func expandWorkspaceProperties(properties []interface{}) *workspaces.WorkspacePr

p := properties[0].(map[string]interface{})

return &workspaces.WorkspaceProperties{
ComputeTypeName: aws.String(p["compute_type_name"].(string)),
RootVolumeSizeGib: aws.Int64(int64(p["root_volume_size_gib"].(int))),
RunningMode: aws.String(p["running_mode"].(string)),
RunningModeAutoStopTimeoutInMinutes: aws.Int64(int64(p["running_mode_auto_stop_timeout_in_minutes"].(int))),
UserVolumeSizeGib: aws.Int64(int64(p["user_volume_size_gib"].(int))),
workspaceProperties := &workspaces.WorkspaceProperties{
ComputeTypeName: aws.String(p["compute_type_name"].(string)),
RootVolumeSizeGib: aws.Int64(int64(p["root_volume_size_gib"].(int))),
RunningMode: aws.String(p["running_mode"].(string)),
UserVolumeSizeGib: aws.Int64(int64(p["user_volume_size_gib"].(int))),
}

if p["running_mode"] == workspaces.RunningModeAutoStop {
workspaceProperties.RunningModeAutoStopTimeoutInMinutes = aws.Int64(int64(p["running_mode_auto_stop_timeout_in_minutes"].(int)))
}

return workspaceProperties
}

func flattenWorkspaceProperties(properties *workspaces.WorkspaceProperties) []map[string]interface{} {
Expand Down
36 changes: 35 additions & 1 deletion aws/resource_aws_workspaces_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,40 @@ func TestAccAwsWorkspacesWorkspace_workspaceProperties(t *testing.T) {
})
}

// TestAccAwsWorkspacesWorkspace_workspaceProperties_runningModeAlwaysOn
// validates workspace resource creation/import when workspace_properties.running_mode is set to ALWAYS_ON
// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/13558
func TestAccAwsWorkspacesWorkspace_workspaceProperties_runningModeAlwaysOn(t *testing.T) {
var v1 workspaces.Workspace
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_workspaces_workspace.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckHasIAMRole(t, "workspaces_DefaultRole") },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsWorkspacesWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccWorkspacesWorkspaceConfig_WorkspacePropertiesB(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsWorkspacesWorkspaceExists(resourceName, &v1),
resource.TestCheckResourceAttr(resourceName, "workspace_properties.#", "1"),
resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.compute_type_name", workspaces.ComputeValue),
resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.root_volume_size_gib", "80"),
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"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAwsWorkspacesWorkspace_validateRootVolumeSize(t *testing.T) {
rName := acctest.RandString(8)

Expand Down Expand Up @@ -234,7 +268,7 @@ func testAccCheckAwsWorkspacesWorkspaceDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).workspacesconn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_workspace" {
if rs.Type != "aws_workspaces_workspace" {
continue
}

Expand Down