Skip to content

Commit 83180ae

Browse files
Added maxUsableWorkstations to workstation Config (#11908) (#8421)
[upstream:a8e718b060267189c83267788e9ae87069295642] Signed-off-by: Modular Magician <[email protected]>
1 parent 00c0628 commit 83180ae

6 files changed

+69
-0
lines changed

.changelog/11908.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 `maxUsableWorkstations` field to `WorkstationConfiguration` resource.
3+
```

google-beta/services/workstations/iam_workstations_workstation_config_generated_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ resource "google_workstations_workstation_config" "default" {
194194
"label" = "key"
195195
}
196196
197+
max_usable_workstations = 1
198+
197199
host {
198200
gce_instance {
199201
machine_type = "e2-standard-4"
@@ -281,6 +283,8 @@ resource "google_workstations_workstation_config" "default" {
281283
"label" = "key"
282284
}
283285
286+
max_usable_workstations = 1
287+
284288
host {
285289
gce_instance {
286290
machine_type = "e2-standard-4"
@@ -386,6 +390,8 @@ resource "google_workstations_workstation_config" "default" {
386390
"label" = "key"
387391
}
388392
393+
max_usable_workstations = 1
394+
389395
host {
390396
gce_instance {
391397
machine_type = "e2-standard-4"
@@ -476,6 +482,8 @@ resource "google_workstations_workstation_config" "default" {
476482
"label" = "key"
477483
}
478484
485+
max_usable_workstations = 1
486+
479487
host {
480488
gce_instance {
481489
machine_type = "e2-standard-4"
@@ -563,6 +571,8 @@ resource "google_workstations_workstation_config" "default" {
563571
"label" = "key"
564572
}
565573
574+
max_usable_workstations = 1
575+
566576
host {
567577
gce_instance {
568578
machine_type = "e2-standard-4"

google-beta/services/workstations/resource_workstations_workstation_config.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
478478
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
479479
Elem: &schema.Schema{Type: schema.TypeString},
480480
},
481+
"max_usable_workstations": {
482+
Type: schema.TypeInt,
483+
Computed: true,
484+
Optional: true,
485+
Description: `Maximum number of workstations under this configuration a user can have workstations.workstation.use permission on. Only enforced on CreateWorkstation API calls on the user issuing the API request.`,
486+
},
481487
"persistent_directories": {
482488
Type: schema.TypeList,
483489
Computed: true,
@@ -745,6 +751,12 @@ func resourceWorkstationsWorkstationConfigCreate(d *schema.ResourceData, meta in
745751
} else if v, ok := d.GetOkExists("disable_tcp_connections"); !tpgresource.IsEmptyValue(reflect.ValueOf(disableTcpConnectionsProp)) && (ok || !reflect.DeepEqual(v, disableTcpConnectionsProp)) {
746752
obj["disableTcpConnections"] = disableTcpConnectionsProp
747753
}
754+
maxUsableWorkstationsProp, err := expandWorkstationsWorkstationConfigMaxUsableWorkstations(d.Get("max_usable_workstations"), d, config)
755+
if err != nil {
756+
return err
757+
} else if v, ok := d.GetOkExists("max_usable_workstations"); !tpgresource.IsEmptyValue(reflect.ValueOf(maxUsableWorkstationsProp)) && (ok || !reflect.DeepEqual(v, maxUsableWorkstationsProp)) {
758+
obj["maxUsableWorkstations"] = maxUsableWorkstationsProp
759+
}
748760
allowedPortsProp, err := expandWorkstationsWorkstationConfigAllowedPorts(d.Get("allowed_ports"), d, config)
749761
if err != nil {
750762
return err
@@ -916,6 +928,9 @@ func resourceWorkstationsWorkstationConfigRead(d *schema.ResourceData, meta inte
916928
if err := d.Set("disable_tcp_connections", flattenWorkstationsWorkstationConfigDisableTcpConnections(res["disableTcpConnections"], d, config)); err != nil {
917929
return fmt.Errorf("Error reading WorkstationConfig: %s", err)
918930
}
931+
if err := d.Set("max_usable_workstations", flattenWorkstationsWorkstationConfigMaxUsableWorkstations(res["maxUsableWorkstations"], d, config)); err != nil {
932+
return fmt.Errorf("Error reading WorkstationConfig: %s", err)
933+
}
919934
if err := d.Set("allowed_ports", flattenWorkstationsWorkstationConfigAllowedPorts(res["allowedPorts"], d, config)); err != nil {
920935
return fmt.Errorf("Error reading WorkstationConfig: %s", err)
921936
}
@@ -1017,6 +1032,12 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in
10171032
} else if v, ok := d.GetOkExists("disable_tcp_connections"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, disableTcpConnectionsProp)) {
10181033
obj["disableTcpConnections"] = disableTcpConnectionsProp
10191034
}
1035+
maxUsableWorkstationsProp, err := expandWorkstationsWorkstationConfigMaxUsableWorkstations(d.Get("max_usable_workstations"), d, config)
1036+
if err != nil {
1037+
return err
1038+
} else if v, ok := d.GetOkExists("max_usable_workstations"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, maxUsableWorkstationsProp)) {
1039+
obj["maxUsableWorkstations"] = maxUsableWorkstationsProp
1040+
}
10201041
allowedPortsProp, err := expandWorkstationsWorkstationConfigAllowedPorts(d.Get("allowed_ports"), d, config)
10211042
if err != nil {
10221043
return err
@@ -1107,6 +1128,10 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in
11071128
updateMask = append(updateMask, "disableTcpConnections")
11081129
}
11091130

1131+
if d.HasChange("max_usable_workstations") {
1132+
updateMask = append(updateMask, "maxUsableWorkstations")
1133+
}
1134+
11101135
if d.HasChange("allowed_ports") {
11111136
updateMask = append(updateMask, "allowedPorts")
11121137
}
@@ -1876,6 +1901,23 @@ func flattenWorkstationsWorkstationConfigDisableTcpConnections(v interface{}, d
18761901
return v
18771902
}
18781903

1904+
func flattenWorkstationsWorkstationConfigMaxUsableWorkstations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1905+
// Handles the string fixed64 format
1906+
if strVal, ok := v.(string); ok {
1907+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
1908+
return intVal
1909+
}
1910+
}
1911+
1912+
// number values are represented as float64
1913+
if floatVal, ok := v.(float64); ok {
1914+
intVal := int(floatVal)
1915+
return intVal
1916+
}
1917+
1918+
return v // let terraform core handle it otherwise
1919+
}
1920+
18791921
func flattenWorkstationsWorkstationConfigAllowedPorts(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
18801922
if v == nil {
18811923
return v
@@ -2765,6 +2807,10 @@ func expandWorkstationsWorkstationConfigDisableTcpConnections(v interface{}, d t
27652807
return v, nil
27662808
}
27672809

2810+
func expandWorkstationsWorkstationConfigMaxUsableWorkstations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2811+
return v, nil
2812+
}
2813+
27682814
func expandWorkstationsWorkstationConfigAllowedPorts(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
27692815
l := v.([]interface{})
27702816
req := make([]interface{}, 0, len(l))

google-beta/services/workstations/resource_workstations_workstation_config_generated_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ resource "google_workstations_workstation_config" "default" {
121121
"label" = "key"
122122
}
123123
124+
max_usable_workstations = 1
125+
124126
host {
125127
gce_instance {
126128
machine_type = "e2-standard-4"

google-beta/services/workstations/resource_workstations_workstation_config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,8 @@ resource "google_workstations_workstation_config" "default" {
811811
labels = {
812812
foo = "bar"
813813
}
814+
815+
max_usable_workstations = 2
814816
815817
lifecycle {
816818
prevent_destroy = true

website/docs/r/workstations_workstation_config.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ resource "google_workstations_workstation_config" "default" {
9999
"label" = "key"
100100
}
101101
102+
max_usable_workstations = 1
103+
102104
host {
103105
gce_instance {
104106
machine_type = "e2-standard-4"
@@ -744,6 +746,10 @@ The following arguments are supported:
744746
(Optional)
745747
Disables support for plain TCP connections in the workstation. By default the service supports TCP connections via a websocket relay. Setting this option to true disables that relay, which prevents the usage of services that require plain tcp connections, such as ssh. When enabled, all communication must occur over https or wss.
746748

749+
* `max_usable_workstations` -
750+
(Optional)
751+
Maximum number of workstations under this configuration a user can have workstations.workstation.use permission on. Only enforced on CreateWorkstation API calls on the user issuing the API request.
752+
747753
* `allowed_ports` -
748754
(Optional)
749755
A list of port ranges specifying single ports or ranges of ports that are externally accessible in the workstation. Allowed ports must be one of 22, 80, or within range 1024-65535. If not specified defaults to ports 22, 80, and ports 1024-65535.

0 commit comments

Comments
 (0)