Skip to content

Commit 23e9c96

Browse files
authored
feat: allow setting network tags on autopilot clusters (terraform-google-modules#1572)
1 parent 67084cd commit 23e9c96

File tree

12 files changed

+49
-1
lines changed

12 files changed

+49
-1
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ resource "google_container_cluster" "primary" {
222222
}
223223
}
224224
}
225+
{% if autopilot_cluster %}
226+
dynamic "node_pool_auto_config" {
227+
for_each = length(var.network_tags) > 0 ? [1] : []
228+
content {
229+
network_tags {
230+
tags = var.network_tags
231+
}
232+
}
233+
}
234+
{% endif %}
225235

226236
master_auth {
227237
client_certificate_config {

autogen/main/variables.tf.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ variable "node_pools_oauth_scopes" {
292292
}
293293
{% endif %}
294294

295+
{% if autopilot_cluster %}
296+
variable "network_tags" {
297+
description = "(Optional, Beta) - List of network tags applied to auto-provisioned node pools."
298+
type = list(string)
299+
default = []
300+
}
301+
{% endif %}
295302
variable "stub_domains" {
296303
type = map(list(string))
297304
description = "Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server"

examples/simple_autopilot_private/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module "gke" {
4848
enable_private_endpoint = true
4949
enable_private_nodes = true
5050
master_ipv4_cidr_block = "172.16.0.0/28"
51+
network_tags = [local.cluster_type]
5152

5253
master_authorized_networks = [
5354
{

examples/simple_autopilot_public/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ module "gke" {
4444
ip_range_services = local.svc_range_name
4545
release_channel = "REGULAR"
4646
enable_vertical_pod_autoscaling = true
47+
network_tags = [local.cluster_type]
4748
}

modules/beta-autopilot-private-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Then perform the following commands on the root folder:
115115
| name | The name of the cluster (required) | `string` | n/a | yes |
116116
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
117117
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
118+
| network\_tags | (Optional, Beta) - List of network tags applied to auto-provisioned node pools. | `list(string)` | `[]` | no |
118119
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | `list(string)` | <pre>[<br> "10.0.0.0/8",<br> "172.16.0.0/12",<br> "192.168.0.0/16"<br>]</pre> | no |
119120
| notification\_config\_topic | The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}. | `string` | `""` | no |
120121
| project\_id | The project ID to host the cluster in (required) | `string` | n/a | yes |

modules/beta-autopilot-private-cluster/cluster.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ resource "google_container_cluster" "primary" {
9494
}
9595
}
9696
}
97+
dynamic "node_pool_auto_config" {
98+
for_each = length(var.network_tags) > 0 ? [1] : []
99+
content {
100+
network_tags {
101+
tags = var.network_tags
102+
}
103+
}
104+
}
97105

98106
master_auth {
99107
client_certificate_config {

modules/beta-autopilot-private-cluster/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ variable "enable_resource_consumption_export" {
167167
}
168168

169169

170+
variable "network_tags" {
171+
description = "(Optional, Beta) - List of network tags applied to auto-provisioned node pools."
172+
type = list(string)
173+
default = []
174+
}
170175
variable "stub_domains" {
171176
type = map(list(string))
172177
description = "Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server"

modules/beta-autopilot-public-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Then perform the following commands on the root folder:
104104
| name | The name of the cluster (required) | `string` | n/a | yes |
105105
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
106106
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
107+
| network\_tags | (Optional, Beta) - List of network tags applied to auto-provisioned node pools. | `list(string)` | `[]` | no |
107108
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | `list(string)` | <pre>[<br> "10.0.0.0/8",<br> "172.16.0.0/12",<br> "192.168.0.0/16"<br>]</pre> | no |
108109
| notification\_config\_topic | The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}. | `string` | `""` | no |
109110
| project\_id | The project ID to host the cluster in (required) | `string` | n/a | yes |

modules/beta-autopilot-public-cluster/cluster.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ resource "google_container_cluster" "primary" {
9494
}
9595
}
9696
}
97+
dynamic "node_pool_auto_config" {
98+
for_each = length(var.network_tags) > 0 ? [1] : []
99+
content {
100+
network_tags {
101+
tags = var.network_tags
102+
}
103+
}
104+
}
97105

98106
master_auth {
99107
client_certificate_config {

modules/beta-autopilot-public-cluster/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ variable "enable_resource_consumption_export" {
167167
}
168168

169169

170+
variable "network_tags" {
171+
description = "(Optional, Beta) - List of network tags applied to auto-provisioned node pools."
172+
type = list(string)
173+
default = []
174+
}
170175
variable "stub_domains" {
171176
type = map(list(string))
172177
description = "Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server"

test/integration/simple_autopilot_private/simple_autopilot_private_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func TestSimpleAutopilotPrivate(t *testing.T) {
5454
g.JSONEq(assert, op, pth)
5555
}
5656
assert.Contains([]string{"RUNNING", "RECONCILING"}, op.Get("status").String())
57+
assert.Contains(op.Get("nodePoolAutoConfig.networkTags.tags").String(), "simple-autopilot-private")
5758
})
5859

5960
bpt.Test()

test/integration/simple_autopilot_public/simple_autopiliot_public_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestSimpleAutopilotPublic(t *testing.T) {
5454
g.JSONEq(assert, op, pth)
5555
}
5656
assert.Contains([]string{"RUNNING", "RECONCILING"}, op.Get("status").String())
57-
57+
assert.Contains(op.Get("nodePoolAutoConfig.networkTags.tags").String(), "simple-autopilot-public")
5858
})
5959

6060
bpt.Test()

0 commit comments

Comments
 (0)