Skip to content

Commit

Permalink
Add support for source_workstation in workstations_workstation resour…
Browse files Browse the repository at this point in the history
…ce. (#12549) (#8938)

[upstream:3141d28edde5caf84cd1fc574408e608c33e03dc]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 17, 2024
1 parent 8f49a84 commit 8b8596c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/12549.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
workstations: add `source_workstation` field to `google_workstations_workstation` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/workstations_workstation.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 8b8596c

Please sign in to comment.