Skip to content

Commit d64862c

Browse files
Set supported PD fields on workstation_config as mutable. (#8000) (#5695)
* Set supported PD fields on workstation_config as mutable. * Revert default for reclaim_policy as it is breaking. Signed-off-by: Modular Magician <[email protected]>
1 parent d65d605 commit d64862c

File tree

5 files changed

+190
-20
lines changed

5 files changed

+190
-20
lines changed

.changelog/8000.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
workstations: Support update of PD fields `reclaim_policy` and `source_snapshot` on `google_workstations_workstation_config` (beta)
3+
```

google-beta/resource_workstations_workstation_config.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,14 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
273273
Type: schema.TypeList,
274274
Computed: true,
275275
Optional: true,
276-
ForceNew: true,
277276
Description: `Directories to persist across workstation sessions.`,
278277
Elem: &schema.Resource{
279278
Schema: map[string]*schema.Schema{
280279
"gce_pd": {
281280
Type: schema.TypeList,
282281
Computed: true,
283282
Optional: true,
284-
ForceNew: true,
285-
Description: `PersistentDirectory backed by a Compute Engine regional persistent disk.`,
283+
Description: `A directory to persist across workstation sessions, backed by a Compute Engine regional persistent disk. Can only be updated if not empty during creation.`,
286284
MaxItems: 1,
287285
Elem: &schema.Resource{
288286
Schema: map[string]*schema.Schema{
@@ -291,34 +289,33 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
291289
Computed: true,
292290
Optional: true,
293291
ForceNew: true,
294-
Description: `Type of the disk to use.`,
292+
Description: `The type of the persistent disk for the home directory. Defaults to 'pd-standard'.`,
295293
},
296294
"fs_type": {
297295
Type: schema.TypeString,
298296
Computed: true,
299297
Optional: true,
300298
ForceNew: true,
301-
Description: `Type of file system that the disk should be formatted with. The workstation image must support this file system type. Must be empty if sourceSnapshot is set.`,
299+
Description: `Type of file system that the disk should be formatted with. The workstation image must support this file system type. Must be empty if 'sourceSnapshot' is set. Defaults to 'ext4'.`,
302300
},
303301
"reclaim_policy": {
304302
Type: schema.TypeString,
305303
Optional: true,
306-
ForceNew: true,
307304
ValidateFunc: verify.ValidateEnum([]string{"DELETE", "RETAIN", ""}),
308-
Description: `What should happen to the disk after the workstation is deleted. Defaults to DELETE. Possible values: ["DELETE", "RETAIN"]`,
305+
Description: `Whether the persistent disk should be deleted when the workstation is deleted. Valid values are 'DELETE' and 'RETAIN'. Defaults to 'DELETE'. Possible values: ["DELETE", "RETAIN"]`,
309306
},
310307
"size_gb": {
311-
Type: schema.TypeInt,
312-
Computed: true,
313-
Optional: true,
314-
ForceNew: true,
315-
Description: `Size of the disk in GB. Must be empty if sourceSnapshot is set.`,
308+
Type: schema.TypeInt,
309+
Computed: true,
310+
Optional: true,
311+
ForceNew: true,
312+
Description: `The GB capacity of a persistent home directory for each workstation created with this configuration. Must be empty if 'sourceSnapshot' is set.
313+
Valid values are '10', '50', '100', '200', '500', or '1000'. Defaults to '200'. If less than '200' GB, the 'diskType' must be 'pd-balanced' or 'pd-ssd'.`,
316314
},
317315
"source_snapshot": {
318316
Type: schema.TypeString,
319317
Optional: true,
320-
ForceNew: true,
321-
Description: `The snapshot to use as the source for the disk. This can be the snapshot's 'self_link', 'id', or a string in the format of 'projects/{project}/global/snapshots/{snapshot}'. If set, sizeGb and fsType must be empty.`,
318+
Description: `Name of the snapshot to use as the source for the disk. This can be the snapshot's 'self_link', 'id', or a string in the format of 'projects/{project}/global/snapshots/{snapshot}'. If set, 'sizeGb' and 'fsType' must be empty. Can only be updated if it has an existing value.`,
322319
},
323320
},
324321
},
@@ -674,6 +671,12 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in
674671
} else if v, ok := d.GetOkExists("host"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, hostProp)) {
675672
obj["host"] = hostProp
676673
}
674+
persistentDirectoriesProp, err := expandWorkstationsWorkstationConfigPersistentDirectories(d.Get("persistent_directories"), d, config)
675+
if err != nil {
676+
return err
677+
} else if v, ok := d.GetOkExists("persistent_directories"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, persistentDirectoriesProp)) {
678+
obj["persistentDirectories"] = persistentDirectoriesProp
679+
}
677680
containerProp, err := expandWorkstationsWorkstationConfigContainer(d.Get("container"), d, config)
678681
if err != nil {
679682
return err
@@ -724,6 +727,10 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in
724727
"host.gceInstance.confidentialInstanceConfig.enableConfidentialCompute")
725728
}
726729

730+
if d.HasChange("persistent_directories") {
731+
updateMask = append(updateMask, "persistentDirectories")
732+
}
733+
727734
if d.HasChange("container") {
728735
updateMask = append(updateMask, "container.image",
729736
"container.command",

google-beta/resource_workstations_workstation_config_generated_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ resource "google_workstations_workstation_config" "default" {
268268
mount_path = "/home"
269269
gce_pd {
270270
size_gb = 200
271+
fs_type = "ext4"
272+
disk_type = "pd-standard"
271273
reclaim_policy = "DELETE"
272274
}
273275
}

google-beta/resource_workstations_workstation_config_test.go

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,158 @@ resource "google_workstations_workstation_config" "default" {
609609
}
610610
`, context)
611611
}
612+
613+
func TestAccWorkstationsWorkstationConfig_updatePersistentDirectorySourceSnapshot(t *testing.T) {
614+
t.Parallel()
615+
616+
context := map[string]interface{}{
617+
"random_suffix": RandString(t, 10),
618+
}
619+
620+
VcrTest(t, resource.TestCase{
621+
PreCheck: func() { AccTestPreCheck(t) },
622+
ProtoV5ProviderFactories: ProtoV5ProviderBetaFactories(t),
623+
CheckDestroy: testAccCheckWorkstationsWorkstationConfigDestroyProducer(t),
624+
Steps: []resource.TestStep{
625+
{
626+
Config: testAccWorkstationsWorkstationConfig_withSourceDiskSnapshot(context),
627+
},
628+
{
629+
ResourceName: "google_workstations_workstation_cluster.default",
630+
ImportState: true,
631+
ImportStateVerify: true,
632+
ImportStateVerifyIgnore: []string{"etag"},
633+
},
634+
{
635+
Config: testAccWorkstationsWorkstationConfig_withUpdatedSourceDiskSnapshot(context),
636+
},
637+
{
638+
ResourceName: "google_workstations_workstation_cluster.default",
639+
ImportState: true,
640+
ImportStateVerify: true,
641+
ImportStateVerifyIgnore: []string{"etag"},
642+
},
643+
},
644+
})
645+
}
646+
647+
func testAccWorkstationsWorkstationConfig_withSourceDiskSnapshot(context map[string]interface{}) string {
648+
return Nprintf(`
649+
resource "google_compute_network" "default" {
650+
provider = google-beta
651+
name = "tf-test-workstation-cluster%{random_suffix}"
652+
auto_create_subnetworks = false
653+
}
654+
655+
resource "google_compute_subnetwork" "default" {
656+
provider = google-beta
657+
name = "tf-test-workstation-cluster%{random_suffix}"
658+
ip_cidr_range = "10.0.0.0/24"
659+
region = "us-central1"
660+
network = google_compute_network.default.name
661+
}
662+
663+
resource "google_compute_disk" "test_source_disk" {
664+
provider = google-beta
665+
name = "tf-test-workstation-source-disk%{random_suffix}"
666+
size = 10
667+
type = "pd-ssd"
668+
zone = "us-central1-a"
669+
}
670+
671+
resource "google_compute_snapshot" "test_source_snapshot" {
672+
provider = google-beta
673+
name = "tf-test-workstation-source-snapshot%{random_suffix}"
674+
source_disk = google_compute_disk.test_source_disk.name
675+
zone = "us-central1-a"
676+
}
677+
678+
resource "google_workstations_workstation_cluster" "default" {
679+
provider = google-beta
680+
workstation_cluster_id = "tf-test-workstation-cluster%{random_suffix}"
681+
network = google_compute_network.default.id
682+
subnetwork = google_compute_subnetwork.default.id
683+
location = "us-central1"
684+
}
685+
686+
resource "google_workstations_workstation_config" "default" {
687+
provider = google-beta
688+
workstation_config_id = "tf-test-workstation-config%{random_suffix}"
689+
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id
690+
location = "us-central1"
691+
692+
persistent_directories {
693+
mount_path = "/home"
694+
695+
gce_pd {
696+
source_snapshot = google_compute_snapshot.test_source_snapshot.id
697+
reclaim_policy = "DELETE"
698+
}
699+
}
700+
}
701+
`, context)
702+
}
703+
704+
func testAccWorkstationsWorkstationConfig_withUpdatedSourceDiskSnapshot(context map[string]interface{}) string {
705+
return Nprintf(`
706+
resource "google_compute_network" "default" {
707+
provider = google-beta
708+
name = "tf-test-workstation-cluster%{random_suffix}"
709+
auto_create_subnetworks = false
710+
}
711+
712+
resource "google_compute_subnetwork" "default" {
713+
provider = google-beta
714+
name = "tf-test-workstation-cluster%{random_suffix}"
715+
ip_cidr_range = "10.0.0.0/24"
716+
region = "us-central1"
717+
network = google_compute_network.default.name
718+
}
719+
720+
resource "google_compute_disk" "test_source_disk" {
721+
provider = google-beta
722+
name = "tf-test-workstation-source-disk%{random_suffix}"
723+
size = 10
724+
type = "pd-ssd"
725+
zone = "us-central1-a"
726+
}
727+
728+
resource "google_compute_snapshot" "test_source_snapshot" {
729+
provider = google-beta
730+
name = "tf-test-workstation-source-snapshot%{random_suffix}"
731+
source_disk = google_compute_disk.test_source_disk.name
732+
zone = "us-central1-a"
733+
}
734+
735+
resource "google_compute_snapshot" "test_source_snapshot2" {
736+
provider = google-beta
737+
name = "tf-test-workstation-source-snapshot2%{random_suffix}"
738+
source_disk = google_compute_disk.test_source_disk.name
739+
zone = "us-central1-a"
740+
}
741+
742+
resource "google_workstations_workstation_cluster" "default" {
743+
provider = google-beta
744+
workstation_cluster_id = "tf-test-workstation-cluster%{random_suffix}"
745+
network = google_compute_network.default.id
746+
subnetwork = google_compute_subnetwork.default.id
747+
location = "us-central1"
748+
}
749+
750+
resource "google_workstations_workstation_config" "default" {
751+
provider = google-beta
752+
workstation_config_id = "tf-test-workstation-config%{random_suffix}"
753+
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id
754+
location = "us-central1"
755+
756+
persistent_directories {
757+
mount_path = "/home"
758+
759+
gce_pd {
760+
source_snapshot = google_compute_snapshot.test_source_snapshot2.id
761+
reclaim_policy = "RETAIN"
762+
}
763+
}
764+
}
765+
`, context)
766+
}

website/docs/r/workstations_workstation_config.html.markdown

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ resource "google_workstations_workstation_config" "default" {
210210
mount_path = "/home"
211211
gce_pd {
212212
size_gb = 200
213+
fs_type = "ext4"
214+
disk_type = "pd-standard"
213215
reclaim_policy = "DELETE"
214216
}
215217
}
@@ -560,32 +562,33 @@ The following arguments are supported:
560562

561563
* `gce_pd` -
562564
(Optional)
563-
PersistentDirectory backed by a Compute Engine regional persistent disk.
565+
A directory to persist across workstation sessions, backed by a Compute Engine regional persistent disk. Can only be updated if not empty during creation.
564566
Structure is [documented below](#nested_gce_pd).
565567

566568

567569
<a name="nested_gce_pd"></a>The `gce_pd` block supports:
568570

569571
* `fs_type` -
570572
(Optional)
571-
Type of file system that the disk should be formatted with. The workstation image must support this file system type. Must be empty if sourceSnapshot is set.
573+
Type of file system that the disk should be formatted with. The workstation image must support this file system type. Must be empty if `sourceSnapshot` is set. Defaults to `ext4`.
572574

573575
* `disk_type` -
574576
(Optional)
575-
Type of the disk to use.
577+
The type of the persistent disk for the home directory. Defaults to `pd-standard`.
576578

577579
* `size_gb` -
578580
(Optional)
579-
Size of the disk in GB. Must be empty if sourceSnapshot is set.
581+
The GB capacity of a persistent home directory for each workstation created with this configuration. Must be empty if `sourceSnapshot` is set.
582+
Valid values are `10`, `50`, `100`, `200`, `500`, or `1000`. Defaults to `200`. If less than `200` GB, the `diskType` must be `pd-balanced` or `pd-ssd`.
580583

581584
* `reclaim_policy` -
582585
(Optional)
583-
What should happen to the disk after the workstation is deleted. Defaults to DELETE.
586+
Whether the persistent disk should be deleted when the workstation is deleted. Valid values are `DELETE` and `RETAIN`. Defaults to `DELETE`.
584587
Possible values are: `DELETE`, `RETAIN`.
585588

586589
* `source_snapshot` -
587590
(Optional)
588-
The snapshot to use as the source for the disk. This can be the snapshot's `self_link`, `id`, or a string in the format of `projects/{project}/global/snapshots/{snapshot}`. If set, sizeGb and fsType must be empty.
591+
Name of the snapshot to use as the source for the disk. This can be the snapshot's `self_link`, `id`, or a string in the format of `projects/{project}/global/snapshots/{snapshot}`. If set, `sizeGb` and `fsType` must be empty. Can only be updated if it has an existing value.
589592

590593
<a name="nested_container"></a>The `container` block supports:
591594

0 commit comments

Comments
 (0)