diff --git a/aws/resource_aws_workspaces_workspace.go b/aws/resource_aws_workspaces_workspace.go index 808534fe6e4..fbd653575bf 100644 --- a/aws/resource_aws_workspaces_workspace.go +++ b/aws/resource_aws_workspaces_workspace.go @@ -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 } @@ -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{} { diff --git a/aws/resource_aws_workspaces_workspace_test.go b/aws/resource_aws_workspaces_workspace_test.go index ca41d084cb3..aab0afcbb92 100644 --- a/aws/resource_aws_workspaces_workspace_test.go +++ b/aws/resource_aws_workspaces_workspace_test.go @@ -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) @@ -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 }