Skip to content

Commit 76e5a0f

Browse files
daanheikensc2thorn
andauthored
Add Beta support for allowedPorts field for Cloud Workstations configurations (#11299)
Co-authored-by: Cameron Thornton <[email protected]>
1 parent 3c185c1 commit 76e5a0f

File tree

3 files changed

+243
-1
lines changed

3 files changed

+243
-1
lines changed

mmv1/products/workstations/WorkstationConfig.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ examples:
119119
account_id: 'my-account'
120120
workstation_cluster_name: 'workstation-cluster'
121121
workstation_config_name: 'workstation-config'
122+
- name: 'workstation_config_allowed_ports'
123+
primary_resource_id: 'default'
124+
min_version: 'beta'
125+
vars:
126+
workstation_cluster_name: 'workstation-cluster'
127+
workstation_config_name: 'workstation-config'
122128
parameters:
123129
- name: 'workstationConfigId'
124130
type: String
@@ -650,6 +656,25 @@ properties:
650656
description: |
651657
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.
652658
min_version: 'beta'
659+
- name: 'allowedPorts'
660+
type: Array
661+
default_from_api: true
662+
description: |
663+
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.
664+
min_version: 'beta'
665+
item_type:
666+
type: NestedObject
667+
properties:
668+
- name: 'first'
669+
type: Integer
670+
description: |
671+
Starting port number for the current range of ports. Valid ports are 22, 80, and ports within the range 1024-65535.
672+
min_version: 'beta'
673+
- name: 'last'
674+
type: Integer
675+
description: |
676+
Ending port number for the current range of ports. Valid ports are 22, 80, and ports within the range 1024-65535.
677+
min_version: 'beta'
653678
- name: 'conditions'
654679
type: Array
655680
description: |-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
resource "google_compute_network" "default" {
2+
provider = google-beta
3+
name = "{{index $.Vars "workstation_cluster_name"}}"
4+
auto_create_subnetworks = false
5+
}
6+
7+
resource "google_compute_subnetwork" "default" {
8+
provider = google-beta
9+
name = "{{index $.Vars "workstation_cluster_name"}}"
10+
ip_cidr_range = "10.0.0.0/24"
11+
region = "us-central1"
12+
network = google_compute_network.default.name
13+
}
14+
15+
resource "google_workstations_workstation_cluster" "{{$.PrimaryResourceId}}" {
16+
provider = google-beta
17+
workstation_cluster_id = "{{index $.Vars "workstation_cluster_name"}}"
18+
network = google_compute_network.default.id
19+
subnetwork = google_compute_subnetwork.default.id
20+
location = "us-central1"
21+
22+
labels = {
23+
"label" = "key"
24+
}
25+
26+
annotations = {
27+
label-one = "value-one"
28+
}
29+
}
30+
31+
resource "google_workstations_workstation_config" "{{$.PrimaryResourceId}}" {
32+
provider = google-beta
33+
workstation_config_id = "{{index $.Vars "workstation_config_name"}}"
34+
workstation_cluster_id = google_workstations_workstation_cluster.{{$.PrimaryResourceId}}.workstation_cluster_id
35+
location = "us-central1"
36+
37+
host {
38+
gce_instance {
39+
machine_type = "e2-standard-4"
40+
boot_disk_size_gb = 35
41+
disable_public_ip_addresses = true
42+
}
43+
}
44+
45+
# Allow only port 80 (HTTP)
46+
allowed_ports {
47+
first = 80
48+
last = 80
49+
}
50+
51+
# Allow only port 22 (SSH)
52+
allowed_ports {
53+
first = 22
54+
last = 22
55+
}
56+
57+
# Allow port range 1024-65535
58+
allowed_ports {
59+
first = 1024
60+
last = 65535
61+
}
62+
}

mmv1/third_party/terraform/services/workstations/resource_workstations_workstation_config_test.go.tmpl

+156-1
Original file line numberDiff line numberDiff line change
@@ -1397,4 +1397,159 @@ resource "google_workstations_workstation_config" "default" {
13971397
`, context)
13981398
}
13991399

1400-
{{ end }}
1400+
func TestAccWorkstationsWorkstationConfig_workstationConfigAllowedPortsUpdate(t *testing.T) {
1401+
t.Parallel()
1402+
1403+
context := map[string]interface{}{
1404+
"random_suffix": acctest.RandString(t, 10),
1405+
}
1406+
1407+
acctest.VcrTest(t, resource.TestCase{
1408+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1409+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
1410+
CheckDestroy: testAccCheckWorkstationsWorkstationConfigDestroyProducer(t),
1411+
Steps: []resource.TestStep{
1412+
{
1413+
Config: testAccWorkstationsWorkstationConfig_workstationConfigAllowedPorts(context),
1414+
},
1415+
{
1416+
ResourceName: "google_workstations_workstation_config.default",
1417+
ImportState: true,
1418+
ImportStateVerify: true,
1419+
ImportStateVerifyIgnore: []string{"annotations", "enable_audit_agent", "labels", "location", "terraform_labels", "workstation_cluster_id", "workstation_config_id"},
1420+
},
1421+
{
1422+
Config: testAccWorkstationsWorkstationConfig_workstationConfigAllowedPortsUpdate(context),
1423+
},
1424+
{
1425+
ResourceName: "google_workstations_workstation_config.default",
1426+
ImportState: true,
1427+
ImportStateVerify: true,
1428+
ImportStateVerifyIgnore: []string{"annotations", "enable_audit_agent", "labels", "location", "terraform_labels", "workstation_cluster_id", "workstation_config_id"},
1429+
},
1430+
},
1431+
})
1432+
}
1433+
1434+
func testAccWorkstationsWorkstationConfig_workstationConfigAllowedPorts(context map[string]interface{}) string {
1435+
return acctest.Nprintf(`
1436+
resource "google_compute_network" "default" {
1437+
provider = google-beta
1438+
name = "tf-test-workstation-cluster%{random_suffix}"
1439+
auto_create_subnetworks = false
1440+
}
1441+
1442+
resource "google_compute_subnetwork" "default" {
1443+
provider = google-beta
1444+
name = "tf-test-workstation-cluster%{random_suffix}"
1445+
ip_cidr_range = "10.0.0.0/24"
1446+
region = "us-central1"
1447+
network = google_compute_network.default.name
1448+
}
1449+
1450+
resource "google_workstations_workstation_cluster" "default" {
1451+
provider = google-beta
1452+
workstation_cluster_id = "tf-test-workstation-cluster%{random_suffix}"
1453+
network = google_compute_network.default.id
1454+
subnetwork = google_compute_subnetwork.default.id
1455+
location = "us-central1"
1456+
1457+
labels = {
1458+
"label" = "key"
1459+
}
1460+
1461+
annotations = {
1462+
label-one = "value-one"
1463+
}
1464+
}
1465+
1466+
resource "google_workstations_workstation_config" "default" {
1467+
provider = google-beta
1468+
workstation_config_id = "tf-test-workstation-config%{random_suffix}"
1469+
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id
1470+
location = "us-central1"
1471+
1472+
host {
1473+
gce_instance {
1474+
machine_type = "e2-standard-4"
1475+
boot_disk_size_gb = 35
1476+
disable_public_ip_addresses = true
1477+
}
1478+
}
1479+
1480+
# Allow only port 80 (HTTP)
1481+
allowed_ports {
1482+
first = 80
1483+
last = 80
1484+
}
1485+
}
1486+
`, context)
1487+
}
1488+
1489+
func testAccWorkstationsWorkstationConfig_workstationConfigAllowedPortsUpdate(context map[string]interface{}) string {
1490+
return acctest.Nprintf(`
1491+
resource "google_compute_network" "default" {
1492+
provider = google-beta
1493+
name = "tf-test-workstation-cluster%{random_suffix}"
1494+
auto_create_subnetworks = false
1495+
}
1496+
1497+
resource "google_compute_subnetwork" "default" {
1498+
provider = google-beta
1499+
name = "tf-test-workstation-cluster%{random_suffix}"
1500+
ip_cidr_range = "10.0.0.0/24"
1501+
region = "us-central1"
1502+
network = google_compute_network.default.name
1503+
}
1504+
1505+
resource "google_workstations_workstation_cluster" "default" {
1506+
provider = google-beta
1507+
workstation_cluster_id = "tf-test-workstation-cluster%{random_suffix}"
1508+
network = google_compute_network.default.id
1509+
subnetwork = google_compute_subnetwork.default.id
1510+
location = "us-central1"
1511+
1512+
labels = {
1513+
"label" = "key"
1514+
}
1515+
1516+
annotations = {
1517+
label-one = "value-one"
1518+
}
1519+
}
1520+
1521+
resource "google_workstations_workstation_config" "default" {
1522+
provider = google-beta
1523+
workstation_config_id = "tf-test-workstation-config%{random_suffix}"
1524+
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id
1525+
location = "us-central1"
1526+
1527+
host {
1528+
gce_instance {
1529+
machine_type = "e2-standard-4"
1530+
boot_disk_size_gb = 35
1531+
disable_public_ip_addresses = true
1532+
}
1533+
}
1534+
1535+
# Allow only port 80 (HTTP)
1536+
allowed_ports {
1537+
first = 80
1538+
last = 80
1539+
}
1540+
1541+
# Allow only port 22 (SSH)
1542+
allowed_ports {
1543+
first = 22
1544+
last = 22
1545+
}
1546+
1547+
# Allow port range 1024-65535
1548+
allowed_ports {
1549+
first = 1024
1550+
last = 65535
1551+
}
1552+
}
1553+
`, context)
1554+
}
1555+
{{- end }}

0 commit comments

Comments
 (0)