Skip to content

Commit 24a7f98

Browse files
Add readiness_checks to google_workstations_workstation_config (#9841) (#6895)
* feat: add `readiness_checks` to Workstation Config * chore: set path and change port to port 80 * Update WorkstationConfig.yaml * chore: make readiness checks arguments required * chore: add readiness checks to basic example * LRevert "chore: add readiness checks to basic example" This reverts commit e8d3ec37c649d86bf03fa978003d07f22caf8d7b. --------- [upstream:7ca983b9aa12655a93b7e9683ddc25ed1bd972ae] Signed-off-by: Modular Magician <[email protected]>
1 parent 1749df9 commit 24a7f98

File tree

4 files changed

+210
-0
lines changed

4 files changed

+210
-0
lines changed

.changelog/9841.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 `readiness_checks` argument block to `google_workstations_workstation_config` resource (beta)
3+
```

google-beta/services/workstations/resource_workstations_workstation_config.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,25 @@ Valid values are '10', '50', '100', '200', '500', or '1000'. Defaults to '200'.
388388
},
389389
},
390390
},
391+
"readiness_checks": {
392+
Type: schema.TypeList,
393+
Optional: true,
394+
Description: `Readiness checks to be performed on a workstation.`,
395+
Elem: &schema.Resource{
396+
Schema: map[string]*schema.Schema{
397+
"path": {
398+
Type: schema.TypeString,
399+
Required: true,
400+
Description: `Path to which the request should be sent.`,
401+
},
402+
"port": {
403+
Type: schema.TypeInt,
404+
Required: true,
405+
Description: `Port to which the request should be sent.`,
406+
},
407+
},
408+
},
409+
},
391410
"replica_zones": {
392411
Type: schema.TypeList,
393412
Computed: true,
@@ -557,6 +576,12 @@ func resourceWorkstationsWorkstationConfigCreate(d *schema.ResourceData, meta in
557576
} else if v, ok := d.GetOkExists("encryption_key"); !tpgresource.IsEmptyValue(reflect.ValueOf(encryptionKeyProp)) && (ok || !reflect.DeepEqual(v, encryptionKeyProp)) {
558577
obj["encryptionKey"] = encryptionKeyProp
559578
}
579+
readinessChecksProp, err := expandWorkstationsWorkstationConfigReadinessChecks(d.Get("readiness_checks"), d, config)
580+
if err != nil {
581+
return err
582+
} else if v, ok := d.GetOkExists("readiness_checks"); !tpgresource.IsEmptyValue(reflect.ValueOf(readinessChecksProp)) && (ok || !reflect.DeepEqual(v, readinessChecksProp)) {
583+
obj["readinessChecks"] = readinessChecksProp
584+
}
560585
disableTcpConnectionsProp, err := expandWorkstationsWorkstationConfigDisableTcpConnections(d.Get("disable_tcp_connections"), d, config)
561586
if err != nil {
562587
return err
@@ -712,6 +737,9 @@ func resourceWorkstationsWorkstationConfigRead(d *schema.ResourceData, meta inte
712737
if err := d.Set("encryption_key", flattenWorkstationsWorkstationConfigEncryptionKey(res["encryptionKey"], d, config)); err != nil {
713738
return fmt.Errorf("Error reading WorkstationConfig: %s", err)
714739
}
740+
if err := d.Set("readiness_checks", flattenWorkstationsWorkstationConfigReadinessChecks(res["readinessChecks"], d, config)); err != nil {
741+
return fmt.Errorf("Error reading WorkstationConfig: %s", err)
742+
}
715743
if err := d.Set("degraded", flattenWorkstationsWorkstationConfigDegraded(res["degraded"], d, config)); err != nil {
716744
return fmt.Errorf("Error reading WorkstationConfig: %s", err)
717745
}
@@ -798,6 +826,12 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in
798826
} else if v, ok := d.GetOkExists("container"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, containerProp)) {
799827
obj["container"] = containerProp
800828
}
829+
readinessChecksProp, err := expandWorkstationsWorkstationConfigReadinessChecks(d.Get("readiness_checks"), d, config)
830+
if err != nil {
831+
return err
832+
} else if v, ok := d.GetOkExists("readiness_checks"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, readinessChecksProp)) {
833+
obj["readinessChecks"] = readinessChecksProp
834+
}
801835
disableTcpConnectionsProp, err := expandWorkstationsWorkstationConfigDisableTcpConnections(d.Get("disable_tcp_connections"), d, config)
802836
if err != nil {
803837
return err
@@ -872,6 +906,10 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in
872906
"container.runAsUser")
873907
}
874908

909+
if d.HasChange("readiness_checks") {
910+
updateMask = append(updateMask, "readinessChecks")
911+
}
912+
875913
if d.HasChange("disable_tcp_connections") {
876914
updateMask = append(updateMask, "disableTcpConnections")
877915
}
@@ -1408,6 +1446,46 @@ func flattenWorkstationsWorkstationConfigEncryptionKeyKmsKeyServiceAccount(v int
14081446
return v
14091447
}
14101448

1449+
func flattenWorkstationsWorkstationConfigReadinessChecks(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1450+
if v == nil {
1451+
return v
1452+
}
1453+
l := v.([]interface{})
1454+
transformed := make([]interface{}, 0, len(l))
1455+
for _, raw := range l {
1456+
original := raw.(map[string]interface{})
1457+
if len(original) < 1 {
1458+
// Do not include empty json objects coming back from the api
1459+
continue
1460+
}
1461+
transformed = append(transformed, map[string]interface{}{
1462+
"path": flattenWorkstationsWorkstationConfigReadinessChecksPath(original["path"], d, config),
1463+
"port": flattenWorkstationsWorkstationConfigReadinessChecksPort(original["port"], d, config),
1464+
})
1465+
}
1466+
return transformed
1467+
}
1468+
func flattenWorkstationsWorkstationConfigReadinessChecksPath(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1469+
return v
1470+
}
1471+
1472+
func flattenWorkstationsWorkstationConfigReadinessChecksPort(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1473+
// Handles the string fixed64 format
1474+
if strVal, ok := v.(string); ok {
1475+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
1476+
return intVal
1477+
}
1478+
}
1479+
1480+
// number values are represented as float64
1481+
if floatVal, ok := v.(float64); ok {
1482+
intVal := int(floatVal)
1483+
return intVal
1484+
}
1485+
1486+
return v // let terraform core handle it otherwise
1487+
}
1488+
14111489
func flattenWorkstationsWorkstationConfigDegraded(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
14121490
return v
14131491
}
@@ -1972,6 +2050,43 @@ func expandWorkstationsWorkstationConfigEncryptionKeyKmsKeyServiceAccount(v inte
19722050
return v, nil
19732051
}
19742052

2053+
func expandWorkstationsWorkstationConfigReadinessChecks(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2054+
l := v.([]interface{})
2055+
req := make([]interface{}, 0, len(l))
2056+
for _, raw := range l {
2057+
if raw == nil {
2058+
continue
2059+
}
2060+
original := raw.(map[string]interface{})
2061+
transformed := make(map[string]interface{})
2062+
2063+
transformedPath, err := expandWorkstationsWorkstationConfigReadinessChecksPath(original["path"], d, config)
2064+
if err != nil {
2065+
return nil, err
2066+
} else if val := reflect.ValueOf(transformedPath); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2067+
transformed["path"] = transformedPath
2068+
}
2069+
2070+
transformedPort, err := expandWorkstationsWorkstationConfigReadinessChecksPort(original["port"], d, config)
2071+
if err != nil {
2072+
return nil, err
2073+
} else if val := reflect.ValueOf(transformedPort); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2074+
transformed["port"] = transformedPort
2075+
}
2076+
2077+
req = append(req, transformed)
2078+
}
2079+
return req, nil
2080+
}
2081+
2082+
func expandWorkstationsWorkstationConfigReadinessChecksPath(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2083+
return v, nil
2084+
}
2085+
2086+
func expandWorkstationsWorkstationConfigReadinessChecksPort(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2087+
return v, nil
2088+
}
2089+
19752090
func expandWorkstationsWorkstationConfigDisableTcpConnections(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
19762091
return v, nil
19772092
}

google-beta/services/workstations/resource_workstations_workstation_config_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,83 @@ func testAccWorkstationsWorkstationConfig_disableTcpConnections(context map[stri
371371
`, context)
372372
}
373373

374+
func TestAccWorkstationsWorkstationConfig_readinessChecks(t *testing.T) {
375+
t.Parallel()
376+
377+
context := map[string]interface{}{
378+
"random_suffix": acctest.RandString(t, 10),
379+
}
380+
381+
acctest.VcrTest(t, resource.TestCase{
382+
PreCheck: func() { acctest.AccTestPreCheck(t) },
383+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
384+
CheckDestroy: testAccCheckWorkstationsWorkstationConfigDestroyProducer(t),
385+
Steps: []resource.TestStep{
386+
{
387+
Config: testAccWorkstationsWorkstationConfig_readinessChecks(context),
388+
},
389+
{
390+
ResourceName: "google_workstations_workstation_cluster.default",
391+
ImportState: true,
392+
ImportStateVerify: true,
393+
ImportStateVerifyIgnore: []string{"etag"},
394+
},
395+
},
396+
})
397+
}
398+
399+
func testAccWorkstationsWorkstationConfig_readinessChecks(context map[string]interface{}) string {
400+
return acctest.Nprintf(`
401+
resource "google_compute_network" "default" {
402+
provider = google-beta
403+
name = "tf-test-workstation-cluster%{random_suffix}"
404+
auto_create_subnetworks = false
405+
}
406+
407+
resource "google_compute_subnetwork" "default" {
408+
provider = google-beta
409+
name = "tf-test-workstation-cluster%{random_suffix}"
410+
ip_cidr_range = "10.0.0.0/24"
411+
region = "us-central1"
412+
network = google_compute_network.default.name
413+
}
414+
415+
resource "google_workstations_workstation_cluster" "default" {
416+
provider = google-beta
417+
workstation_cluster_id = "tf-test-workstation-cluster%{random_suffix}"
418+
network = google_compute_network.default.id
419+
subnetwork = google_compute_subnetwork.default.id
420+
location = "us-central1"
421+
}
422+
423+
resource "google_service_account" "default" {
424+
provider = google-beta
425+
426+
account_id = "tf-test-my-account%{random_suffix}"
427+
display_name = "Service Account"
428+
}
429+
430+
resource "google_workstations_workstation_config" "default" {
431+
provider = google-beta
432+
workstation_config_id = "tf-test-workstation-config%{random_suffix}"
433+
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id
434+
location = "us-central1"
435+
436+
readiness_checks {
437+
path = "/"
438+
port = 80
439+
}
440+
441+
host {
442+
gce_instance {
443+
service_account = google_service_account.default.email
444+
service_account_scopes = ["https://www.googleapis.com/auth/cloud-platform"]
445+
}
446+
}
447+
}
448+
`, context)
449+
}
450+
374451
func TestAccWorkstationsWorkstationConfig_update(t *testing.T) {
375452
t.Parallel()
376453

website/docs/r/workstations_workstation_config.html.markdown

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ The following arguments are supported:
573573
If the encryption key is revoked, the workstation session will automatically be stopped within 7 hours.
574574
Structure is [documented below](#nested_encryption_key).
575575

576+
* `readiness_checks` -
577+
(Optional)
578+
Readiness checks to be performed on a workstation.
579+
Structure is [documented below](#nested_readiness_checks).
580+
576581
* `disable_tcp_connections` -
577582
(Optional)
578583
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.
@@ -743,6 +748,16 @@ The following arguments are supported:
743748
(Required)
744749
The service account to use with the specified KMS key.
745750

751+
<a name="nested_readiness_checks"></a>The `readiness_checks` block supports:
752+
753+
* `path` -
754+
(Required)
755+
Path to which the request should be sent.
756+
757+
* `port` -
758+
(Required)
759+
Port to which the request should be sent.
760+
746761
## Attributes Reference
747762

748763
In addition to the arguments listed above, the following computed attributes are exported:

0 commit comments

Comments
 (0)