Skip to content

Commit

Permalink
refactor and add acceptance test for always_on workspace property
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Aug 26, 2020
1 parent 29a5c0b commit f572e2a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
28 changes: 12 additions & 16 deletions aws/resource_aws_workspaces_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func resourceAwsWorkspacesWorkspaceUpdate(d *schema.ResourceData, meta interface
}
}

if d.HasChange("workspace_properties.0.running_mode_auto_stop_timeout_in_minutes") || (d.Get("workspace_properties.0.running_mode") != workspaces.RunningModeAlwaysOn) {
if d.HasChange("workspace_properties.0.running_mode_auto_stop_timeout_in_minutes") {
if err := workspacePropertyUpdate("running_mode_auto_stop_timeout_in_minutes", conn, d); err != nil {
return err
}
Expand Down Expand Up @@ -366,22 +366,18 @@ func expandWorkspaceProperties(properties []interface{}) *workspaces.WorkspacePr

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

if p["running_mode"] == workspaces.RunningModeAlwaysOn {
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)),
UserVolumeSizeGib: aws.Int64(int64(p["user_volume_size_gib"].(int))),
}
} else {
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

0 comments on commit f572e2a

Please sign in to comment.