From fd44aa902a2913409f99854aa9f1cc4742f0b792 Mon Sep 17 00:00:00 2001 From: Stefan Freitag Date: Wed, 15 Jan 2025 20:50:28 +0100 Subject: [PATCH 1/3] fix: update comparison --- internal/service/workspaces/workspace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/workspaces/workspace.go b/internal/service/workspaces/workspace.go index bfec6562c35..4b4f05b7909 100644 --- a/internal/service/workspaces/workspace.go +++ b/internal/service/workspaces/workspace.go @@ -314,7 +314,7 @@ func workspacePropertyUpdate(ctx context.Context, conn *workspaces.Client, d *sc RunningMode: types.RunningMode(d.Get(key).(string)), } case "workspace_properties.0.running_mode_auto_stop_timeout_in_minutes": - if d.Get("workspace_properties.0.running_mode") != types.RunningModeAutoStop { + if d.Get("workspace_properties.0.running_mode") != string(types.RunningModeAutoStop) { log.Printf("[DEBUG] Property running_mode_auto_stop_timeout_in_minutes makes sense only for AUTO_STOP running mode") return nil } From b347483281015108f22bd53cff5710a46b93ec39 Mon Sep 17 00:00:00 2001 From: Stefan Freitag Date: Thu, 16 Jan 2025 21:20:27 +0100 Subject: [PATCH 2/3] chore: add changelog --- .changelog/40953.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/40953.txt diff --git a/.changelog/40953.txt b/.changelog/40953.txt new file mode 100644 index 00000000000..65ccce8d469 --- /dev/null +++ b/.changelog/40953.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_workspaces_workspace: Fixes value conversion error. +``` \ No newline at end of file From bbc86d88f390cbba59dab73297d938b281f21f25 Mon Sep 17 00:00:00 2001 From: Stefan Freitag Date: Tue, 21 Jan 2025 19:47:10 +0100 Subject: [PATCH 3/3] feat: add tests --- internal/service/workspaces/workspace_test.go | 73 +++++++++++++++++++ .../service/workspaces/workspaces_test.go | 3 +- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/internal/service/workspaces/workspace_test.go b/internal/service/workspaces/workspace_test.go index e61d361c968..f81585f1e0c 100644 --- a/internal/service/workspaces/workspace_test.go +++ b/internal/service/workspaces/workspace_test.go @@ -194,6 +194,54 @@ func testAccWorkspace_workspaceProperties(t *testing.T) { }) } +func testAccWorkspace_workspaceProperties_runningModeAutoStopTimeoutInMinutes(t *testing.T) { + ctx := acctest.Context(t) + var v1 types.Workspace + rName := sdkacctest.RandString(8) + domain := acctest.RandomDomainName() + + resourceName := "aws_workspaces_workspace.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheckDirectory(ctx, t) + acctest.PreCheckDirectoryServiceSimpleDirectory(ctx, t) + acctest.PreCheckHasIAMRole(ctx, t, "workspaces_DefaultRole") + }, + ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(workspaces.ServiceID)), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckWorkspaceDestroy(ctx), + Steps: []resource.TestStep{ + { + Destroy: false, + Config: testAccWorkspaceConfig_propertiesAutoStopTimeoutInMinutes(rName, domain, 120), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckWorkspaceExists(ctx, resourceName, &v1), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.#", "1"), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.compute_type_name", string(types.ComputeValue)), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.root_volume_size_gib", "80"), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.running_mode", string(types.RunningModeAutoStop)), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.running_mode_auto_stop_timeout_in_minutes", "120"), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.user_volume_size_gib", "10"), + ), + }, + { + Config: testAccWorkspaceConfig_propertiesAutoStopTimeoutInMinutes(rName, domain, 180), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckWorkspaceExists(ctx, resourceName, &v1), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.#", "1"), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.compute_type_name", string(types.ComputeValue)), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.root_volume_size_gib", "80"), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.running_mode", string(types.RunningModeAutoStop)), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.running_mode_auto_stop_timeout_in_minutes", "180"), + resource.TestCheckResourceAttr(resourceName, "workspace_properties.0.user_volume_size_gib", "10"), + ), + }, + }, + }) +} + // testAccWorkspace_workspaceProperties_runningModeAlwaysOn // validates workspace resource creation/import when workspace_properties.running_mode is set to ALWAYS_ON // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/13558 @@ -554,6 +602,31 @@ resource "aws_workspaces_workspace" "test" { `, rName)) } +func testAccWorkspaceConfig_propertiesAutoStopTimeoutInMinutes(rName, domain string, autoStoptimeoutInMinutes int) string { + return acctest.ConfigCompose( + testAccWorkspaceConfig_Prerequisites(rName, domain), + 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" + + workspace_properties { + # NOTE: Compute type and volume size update not allowed within 6 hours after creation. + running_mode = "AUTO_STOP" + running_mode_auto_stop_timeout_in_minutes = %[2]d + } + + tags = { + Name = "tf-testacc-workspaces-workspace-%[1]s" + } +} +`, rName, autoStoptimeoutInMinutes)) +} + func testAccWorkspaceConfig_validateRootVolumeSize(rName, domain string) string { return acctest.ConfigCompose( testAccWorkspaceConfig_Prerequisites(rName, domain), diff --git a/internal/service/workspaces/workspaces_test.go b/internal/service/workspaces/workspaces_test.go index 6946d304304..baf13436dd6 100644 --- a/internal/service/workspaces/workspaces_test.go +++ b/internal/service/workspaces/workspaces_test.go @@ -39,7 +39,8 @@ func TestAccWorkSpaces_serial(t *testing.T) { "validateRootVolumeSize": testAccWorkspace_validateRootVolumeSize, "validateUserVolumeSize": testAccWorkspace_validateUserVolumeSize, "workspaceProperties": testAccWorkspace_workspaceProperties, - "workspaceProperties_runningModeAlwaysOn": testAccWorkspace_workspaceProperties_runningModeAlwaysOn, + "workspaceProperties_runningModeAlwaysOn": testAccWorkspace_workspaceProperties_runningModeAlwaysOn, + "workspaceProperties_runningModeAutoStopTimeoutInMinutes": testAccWorkspace_workspaceProperties_runningModeAutoStopTimeoutInMinutes, }, }