Skip to content

Commit 2eeed8b

Browse files
feat: add env block to cloud workstations resource. (#8911) (#6258)
Signed-off-by: Modular Magician <[email protected]>
1 parent fa9fa8f commit 2eeed8b

File tree

6 files changed

+83
-0
lines changed

6 files changed

+83
-0
lines changed

.changelog/8911.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: added `env` field to `google_workstations_workstation` resource (beta)
3+
```

google-beta/services/workstations/iam_workstations_workstation_generated_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ resource "google_workstations_workstation" "default" {
181181
"label" = "key"
182182
}
183183
184+
env = {
185+
name = "foo"
186+
}
187+
184188
annotations = {
185189
label-one = "value-one"
186190
}
@@ -257,6 +261,10 @@ resource "google_workstations_workstation" "default" {
257261
"label" = "key"
258262
}
259263
264+
env = {
265+
name = "foo"
266+
}
267+
260268
annotations = {
261269
label-one = "value-one"
262270
}
@@ -352,6 +360,10 @@ resource "google_workstations_workstation" "default" {
352360
"label" = "key"
353361
}
354362
363+
env = {
364+
name = "foo"
365+
}
366+
355367
annotations = {
356368
label-one = "value-one"
357369
}
@@ -431,6 +443,10 @@ resource "google_workstations_workstation" "default" {
431443
"label" = "key"
432444
}
433445
446+
env = {
447+
name = "foo"
448+
}
449+
434450
annotations = {
435451
label-one = "value-one"
436452
}
@@ -507,6 +523,10 @@ resource "google_workstations_workstation" "default" {
507523
"label" = "key"
508524
}
509525
526+
env = {
527+
name = "foo"
528+
}
529+
510530
annotations = {
511531
label-one = "value-one"
512532
}

google-beta/services/workstations/resource_workstations_workstation.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ func ResourceWorkstationsWorkstation() *schema.Resource {
8383
Optional: true,
8484
Description: `Human-readable name for this resource.`,
8585
},
86+
"env": {
87+
Type: schema.TypeMap,
88+
Optional: true,
89+
Description: `'Client-specified environment variables passed to the workstation container's entrypoint.'`,
90+
Elem: &schema.Schema{Type: schema.TypeString},
91+
},
8692
"labels": {
8793
Type: schema.TypeMap,
8894
Optional: true,
@@ -153,6 +159,12 @@ func resourceWorkstationsWorkstationCreate(d *schema.ResourceData, meta interfac
153159
} else if v, ok := d.GetOkExists("annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(annotationsProp)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
154160
obj["annotations"] = annotationsProp
155161
}
162+
envProp, err := expandWorkstationsWorkstationEnv(d.Get("env"), d, config)
163+
if err != nil {
164+
return err
165+
} else if v, ok := d.GetOkExists("env"); !tpgresource.IsEmptyValue(reflect.ValueOf(envProp)) && (ok || !reflect.DeepEqual(v, envProp)) {
166+
obj["env"] = envProp
167+
}
156168

157169
url, err := tpgresource.ReplaceVars(d, config, "{{WorkstationsBasePath}}projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}/workstationConfigs/{{workstation_config_id}}/workstations?workstationId={{workstation_id}}")
158170
if err != nil {
@@ -263,6 +275,9 @@ func resourceWorkstationsWorkstationRead(d *schema.ResourceData, meta interface{
263275
if err := d.Set("annotations", flattenWorkstationsWorkstationAnnotations(res["annotations"], d, config)); err != nil {
264276
return fmt.Errorf("Error reading Workstation: %s", err)
265277
}
278+
if err := d.Set("env", flattenWorkstationsWorkstationEnv(res["env"], d, config)); err != nil {
279+
return fmt.Errorf("Error reading Workstation: %s", err)
280+
}
266281
if err := d.Set("create_time", flattenWorkstationsWorkstationCreateTime(res["createTime"], d, config)); err != nil {
267282
return fmt.Errorf("Error reading Workstation: %s", err)
268283
}
@@ -310,6 +325,12 @@ func resourceWorkstationsWorkstationUpdate(d *schema.ResourceData, meta interfac
310325
} else if v, ok := d.GetOkExists("annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
311326
obj["annotations"] = annotationsProp
312327
}
328+
envProp, err := expandWorkstationsWorkstationEnv(d.Get("env"), d, config)
329+
if err != nil {
330+
return err
331+
} else if v, ok := d.GetOkExists("env"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, envProp)) {
332+
obj["env"] = envProp
333+
}
313334

314335
url, err := tpgresource.ReplaceVars(d, config, "{{WorkstationsBasePath}}projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}/workstationConfigs/{{workstation_config_id}}/workstations/{{workstation_id}}")
315336
if err != nil {
@@ -330,6 +351,10 @@ func resourceWorkstationsWorkstationUpdate(d *schema.ResourceData, meta interfac
330351
if d.HasChange("annotations") {
331352
updateMask = append(updateMask, "annotations")
332353
}
354+
355+
if d.HasChange("env") {
356+
updateMask = append(updateMask, "env")
357+
}
333358
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
334359
// won't set it
335360
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -462,6 +487,10 @@ func flattenWorkstationsWorkstationAnnotations(v interface{}, d *schema.Resource
462487
return v
463488
}
464489

490+
func flattenWorkstationsWorkstationEnv(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
491+
return v
492+
}
493+
465494
func flattenWorkstationsWorkstationCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
466495
return v
467496
}
@@ -499,3 +528,14 @@ func expandWorkstationsWorkstationAnnotations(v interface{}, d tpgresource.Terra
499528
}
500529
return m, nil
501530
}
531+
532+
func expandWorkstationsWorkstationEnv(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
533+
if v == nil {
534+
return map[string]string{}, nil
535+
}
536+
m := make(map[string]string)
537+
for k, val := range v.(map[string]interface{}) {
538+
m[k] = val.(string)
539+
}
540+
return m, nil
541+
}

google-beta/services/workstations/resource_workstations_workstation_generated_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ resource "google_workstations_workstation" "default" {
113113
"label" = "key"
114114
}
115115
116+
env = {
117+
name = "foo"
118+
}
119+
116120
annotations = {
117121
label-one = "value-one"
118122
}

google-beta/services/workstations/resource_workstations_workstation_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ resource "google_workstations_workstation" "default" {
8787
labels = {
8888
foo = "bar"
8989
}
90+
91+
env = {
92+
name = "bar"
93+
}
9094
}
9195
`, context)
9296
}
@@ -136,6 +140,10 @@ resource "google_workstations_workstation" "default" {
136140
labels = {
137141
foo = "bar"
138142
}
143+
144+
env = {
145+
name = "test"
146+
}
139147
}
140148
`, context)
141149
}

website/docs/r/workstations_workstation.html.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ resource "google_workstations_workstation" "default" {
9595
"label" = "key"
9696
}
9797
98+
env = {
99+
name = "foo"
100+
}
101+
98102
annotations = {
99103
label-one = "value-one"
100104
}
@@ -138,6 +142,10 @@ The following arguments are supported:
138142
(Optional)
139143
Client-specified annotations. This is distinct from labels.
140144

145+
* `env` -
146+
(Optional)
147+
'Client-specified environment variables passed to the workstation container's entrypoint.'
148+
141149
* `project` - (Optional) The ID of the project in which the resource belongs.
142150
If it is not provided, the provider project is used.
143151

0 commit comments

Comments
 (0)