From 8b8596cf25757c5957eafbee95429c3c4b69dc0c Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 17 Dec 2024 13:08:27 -0800 Subject: [PATCH] Add support for source_workstation in workstations_workstation resource. (#12549) (#8938) [upstream:3141d28edde5caf84cd1fc574408e608c33e03dc] Signed-off-by: Modular Magician --- .changelog/12549.txt | 3 +++ .../resource_workstations_workstation.go | 24 +++++++++++++++++++ .../r/workstations_workstation.html.markdown | 5 ++++ 3 files changed, 32 insertions(+) create mode 100644 .changelog/12549.txt diff --git a/.changelog/12549.txt b/.changelog/12549.txt new file mode 100644 index 0000000000..ebb6ef54f0 --- /dev/null +++ b/.changelog/12549.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +workstations: add `source_workstation` field to `google_workstations_workstation` resource +``` \ No newline at end of file diff --git a/google-beta/services/workstations/resource_workstations_workstation.go b/google-beta/services/workstations/resource_workstations_workstation.go index 1fbc9ddcc2..e17fe7c0fc 100644 --- a/google-beta/services/workstations/resource_workstations_workstation.go +++ b/google-beta/services/workstations/resource_workstations_workstation.go @@ -109,6 +109,13 @@ Please refer to the field 'effective_annotations' for all of the annotations pre Please refer to the field 'effective_labels' for all of the labels present on the resource.`, Elem: &schema.Schema{Type: schema.TypeString}, }, + "source_workstation": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: `Full resource name of the source workstation from which the workstation's persistent +directories will be cloned from during creation.`, + }, "create_time": { Type: schema.TypeString, Computed: true, @@ -186,6 +193,12 @@ func resourceWorkstationsWorkstationCreate(d *schema.ResourceData, meta interfac } else if v, ok := d.GetOkExists("env"); !tpgresource.IsEmptyValue(reflect.ValueOf(envProp)) && (ok || !reflect.DeepEqual(v, envProp)) { obj["env"] = envProp } + source_workstationProp, err := expandWorkstationsWorkstationSourceWorkstation(d.Get("source_workstation"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("source_workstation"); !tpgresource.IsEmptyValue(reflect.ValueOf(source_workstationProp)) && (ok || !reflect.DeepEqual(v, source_workstationProp)) { + obj["source_workstation"] = source_workstationProp + } labelsProp, err := expandWorkstationsWorkstationEffectiveLabels(d.Get("effective_labels"), d, config) if err != nil { return err @@ -324,6 +337,9 @@ func resourceWorkstationsWorkstationRead(d *schema.ResourceData, meta interface{ if err := d.Set("state", flattenWorkstationsWorkstationState(res["state"], d, config)); err != nil { return fmt.Errorf("Error reading Workstation: %s", err) } + if err := d.Set("source_workstation", flattenWorkstationsWorkstationSourceWorkstation(res["source_workstation"], d, config)); err != nil { + return fmt.Errorf("Error reading Workstation: %s", err) + } if err := d.Set("terraform_labels", flattenWorkstationsWorkstationTerraformLabels(res["labels"], d, config)); err != nil { return fmt.Errorf("Error reading Workstation: %s", err) } @@ -579,6 +595,10 @@ func flattenWorkstationsWorkstationState(v interface{}, d *schema.ResourceData, return v } +func flattenWorkstationsWorkstationSourceWorkstation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenWorkstationsWorkstationTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return v @@ -617,6 +637,10 @@ func expandWorkstationsWorkstationEnv(v interface{}, d tpgresource.TerraformReso return m, nil } +func expandWorkstationsWorkstationSourceWorkstation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandWorkstationsWorkstationEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { if v == nil { return map[string]string{}, nil diff --git a/website/docs/r/workstations_workstation.html.markdown b/website/docs/r/workstations_workstation.html.markdown index 9107ab0698..f1bd6c9621 100644 --- a/website/docs/r/workstations_workstation.html.markdown +++ b/website/docs/r/workstations_workstation.html.markdown @@ -150,6 +150,11 @@ The following arguments are supported: (Optional) 'Client-specified environment variables passed to the workstation container's entrypoint.' +* `source_workstation` - + (Optional) + Full resource name of the source workstation from which the workstation's persistent + directories will be cloned from during creation. + * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.