Skip to content

Commit cab383b

Browse files
committed
feat: add support for NAP/autopilot resource manager tags
1 parent 30c08c5 commit cab383b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+196
-42
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Then perform the following commands on the root folder:
234234
| network\_policy | Enable network policy addon | `bool` | `false` | no |
235235
| network\_policy\_provider | The network policy provider. | `string` | `"CALICO"` | no |
236236
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
237-
| network\_tags | (Optional) - List of network tags applied to auto-provisioned node pools. | `list(string)` | `[]` | no |
237+
| network\_tags | (Optional) - List of network tags applied to autopilot and auto-provisioned node pools. | `list(string)` | `[]` | no |
238238
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA"` | no |
239239
| node\_pools | List of maps containing node pools | `list(map(any))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
240240
| node\_pools\_cgroup\_mode | Map of strings containing cgroup node config by node-pool name | `map(string)` | <pre>{<br> "all": "",<br> "default-node-pool": ""<br>}</pre> | no |
@@ -260,6 +260,7 @@ Then perform the following commands on the root folder:
260260
| registry\_project\_ids | Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` and `artifactregsitry.reader` roles are assigned on these projects. | `list(string)` | `[]` | no |
261261
| release\_channel | The release channel of this cluster. Accepted values are `UNSPECIFIED`, `RAPID`, `REGULAR` and `STABLE`. Defaults to `REGULAR`. | `string` | `"REGULAR"` | no |
262262
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | `bool` | `false` | no |
263+
| resource\_manager\_tags | (Optional) - List of resource manager tags applied to autopilot and auto-provisioned node pools. A maximum of 5 tags can be specified. Tags must be in one of these formats: `tagKeys/{tag_key_id}=tagValues/{tag_value_id}`, `{org_id}/{tag_key_name}={tag_value_name}`, `{project_id}/{tag_key_name}={tag_value_name}` | `map(string)` | `{}` | no |
263264
| resource\_usage\_export\_dataset\_id | The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export. | `string` | `""` | no |
264265
| security\_posture\_mode | Security posture mode. Accepted values are `DISABLED` and `BASIC`. Defaults to `DISABLED`. | `string` | `"DISABLED"` | no |
265266
| security\_posture\_vulnerability\_mode | Security posture vulnerability mode. Accepted values are `VULNERABILITY_DISABLED`, `VULNERABILITY_BASIC`, and `VULNERABILITY_ENTERPRISE`. Defaults to `VULNERABILITY_DISABLED`. | `string` | `"VULNERABILITY_DISABLED"` | no |

autogen/main/cluster.tf.tmpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ resource "google_container_cluster" "primary" {
329329
}
330330
{% if autopilot_cluster %}
331331
dynamic "node_pool_auto_config" {
332-
for_each = length(var.network_tags) > 0 || var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules || var.add_shadow_firewall_rules || var.insecure_kubelet_readonly_port_enabled != null || var.node_pools_cgroup_mode != null ? [1] : []
332+
for_each = length(var.network_tags) > 0 || length(var.resource_manager_tags) > 0 || var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules || var.add_shadow_firewall_rules || var.insecure_kubelet_readonly_port_enabled != null || var.node_pools_cgroup_mode != null ? [1] : []
333333
content {
334334
dynamic "network_tags" {
335335
for_each = length(var.network_tags) > 0 || var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules || var.add_shadow_firewall_rules ? [1] : []
@@ -338,6 +338,8 @@ resource "google_container_cluster" "primary" {
338338
}
339339
}
340340

341+
resource_manager_tags = length(var.resource_manager_tags) > 0 ? var.resource_manager_tags : null
342+
341343
dynamic "node_kubelet_config" {
342344
for_each = var.insecure_kubelet_readonly_port_enabled != null ? [1] : []
343345
content {
@@ -356,7 +358,7 @@ resource "google_container_cluster" "primary" {
356358

357359
{% if autopilot_cluster != true %}
358360
dynamic "node_pool_auto_config" {
359-
for_each = var.cluster_autoscaling.enabled && (length(var.network_tags) > 0 || var.add_cluster_firewall_rules || local.node_pools_cgroup_mode != null) ? [1] : []
361+
for_each = var.cluster_autoscaling.enabled && (length(var.network_tags) > 0 || length(var.resource_manager_tags) > 0 || var.add_cluster_firewall_rules || local.node_pools_cgroup_mode != null) ? [1] : []
360362
content {
361363
dynamic "network_tags" {
362364
for_each = var.cluster_autoscaling.enabled && (length(var.network_tags) > 0 || var.add_cluster_firewall_rules) ? [1] : []
@@ -365,6 +367,8 @@ resource "google_container_cluster" "primary" {
365367
}
366368
}
367369

370+
resource_manager_tags = length(var.resource_manager_tags) > 0 ? var.resource_manager_tags : null
371+
368372
dynamic "linux_node_config" {
369373
for_each = local.node_pools_cgroup_mode["all"] != "" ? [1] : []
370374
content {

autogen/main/variables.tf.tmpl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,17 @@ variable "node_pools_oauth_scopes" {
400400
{% endif %}
401401

402402
variable "network_tags" {
403-
description = "(Optional) - List of network tags applied to auto-provisioned node pools."
403+
description = "(Optional) - List of network tags applied to autopilot and auto-provisioned node pools."
404404
type = list(string)
405405
default = []
406406
}
407407

408+
variable "resource_manager_tags" {
409+
description = "(Optional) - List of resource manager tags applied to autopilot and auto-provisioned node pools. A maximum of 5 tags can be specified. Tags must be in one of these formats: \"tagKeys/{tag_key_id}\"=\"tagValues/{tag_value_id}\", \"{org_id}/{tag_key_name}\"=\"{tag_value_name}\", \"{project_id}/{tag_key_name}\"=\"{tag_value_name}\"."
410+
type = map(string)
411+
default = {}
412+
}
413+
408414
variable "enable_k8s_beta_apis" {
409415
description = "(Optional) - List of Kubernetes Beta APIs to enable in cluster."
410416
type = list(string)

cluster.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ resource "google_container_cluster" "primary" {
265265
}
266266

267267
dynamic "node_pool_auto_config" {
268-
for_each = var.cluster_autoscaling.enabled && (length(var.network_tags) > 0 || var.add_cluster_firewall_rules || local.node_pools_cgroup_mode != null) ? [1] : []
268+
for_each = var.cluster_autoscaling.enabled && (length(var.network_tags) > 0 || length(var.resource_manager_tags) > 0 || var.add_cluster_firewall_rules || local.node_pools_cgroup_mode != null) ? [1] : []
269269
content {
270270
dynamic "network_tags" {
271271
for_each = var.cluster_autoscaling.enabled && (length(var.network_tags) > 0 || var.add_cluster_firewall_rules) ? [1] : []
@@ -274,6 +274,8 @@ resource "google_container_cluster" "primary" {
274274
}
275275
}
276276

277+
resource_manager_tags = length(var.resource_manager_tags) > 0 ? var.resource_manager_tags : null
278+
277279
dynamic "linux_node_config" {
278280
for_each = local.node_pools_cgroup_mode["all"] != "" ? [1] : []
279281
content {

examples/node_pool/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ module "gke" {
163163
}
164164

165165
node_pools_cgroup_mode = {
166-
all = "CGROUP_MODE_V2"
166+
all = "CGROUP_MODE_V2"
167167
pool-01 = "CGROUP_MODE_V1"
168168
}
169169

metadata.display.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ spec:
387387
remove_default_node_pool:
388388
name: remove_default_node_pool
389389
title: Remove Default Node Pool
390+
resource_manager_tags:
391+
name: resource_manager_tags
392+
title: Resource Manager Tags
390393
resource_usage_export_dataset_id:
391394
name: resource_usage_export_dataset_id
392395
title: Resource Usage Export Dataset Id

metadata.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,13 @@ spec:
404404
- https://www.googleapis.com/auth/cloud-platform
405405
default-node-pool: []
406406
- name: network_tags
407-
description: (Optional) - List of network tags applied to auto-provisioned node pools.
407+
description: (Optional) - List of network tags applied to autopilot and auto-provisioned node pools.
408408
varType: list(string)
409409
defaultValue: []
410+
- name: resource_manager_tags
411+
description: "(Optional) - List of resource manager tags applied to autopilot and auto-provisioned node pools. A maximum of 5 tags can be specified. Tags must be in one of these formats: `tagKeys/{tag_key_id}=tagValues/{tag_value_id}`, `{org_id}/{tag_key_name}={tag_value_name}`, `{project_id}/{tag_key_name}={tag_value_name}`"
412+
varType: map(string)
413+
defaultValue: {}
410414
- name: enable_k8s_beta_apis
411415
description: (Optional) - List of Kubernetes Beta APIs to enable in cluster.
412416
varType: list(string)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Then perform the following commands on the root folder:
144144
| name | The name of the cluster (required) | `string` | n/a | yes |
145145
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
146146
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
147-
| network\_tags | (Optional) - List of network tags applied to auto-provisioned node pools. | `list(string)` | `[]` | no |
147+
| network\_tags | (Optional) - List of network tags applied to autopilot and auto-provisioned node pools. | `list(string)` | `[]` | no |
148148
| node\_pools\_cgroup\_mode | Specifies the Linux cgroup mode for autopilot Kubernetes nodes in the cluster. Accepted values are `CGROUP_MODE_UNSPECIFIED`, `CGROUP_MODE_V1`, and `CGROUP_MODE_V2`, which determine the control group hierarchy used for resource management. | `string` | `null` | no |
149149
| notification\_config\_topic | The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}. | `string` | `""` | no |
150150
| notification\_filter\_event\_type | Choose what type of notifications you want to receive. If no filters are applied, you'll receive all notification types. Can be used to filter what notifications are sent. Accepted values are UPGRADE\_AVAILABLE\_EVENT, UPGRADE\_EVENT, and SECURITY\_BULLETIN\_EVENT. | `list(string)` | `[]` | no |
@@ -156,6 +156,7 @@ Then perform the following commands on the root folder:
156156
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | `bool` | `true` | no |
157157
| registry\_project\_ids | Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` and `artifactregsitry.reader` roles are assigned on these projects. | `list(string)` | `[]` | no |
158158
| release\_channel | The release channel of this cluster. Accepted values are `UNSPECIFIED`, `RAPID`, `REGULAR` and `STABLE`. Defaults to `REGULAR`. | `string` | `"REGULAR"` | no |
159+
| resource\_manager\_tags | (Optional) - List of resource manager tags applied to autopilot and auto-provisioned node pools. A maximum of 5 tags can be specified. Tags must be in one of these formats: `tagKeys/{tag_key_id}=tagValues/{tag_value_id}`, `{org_id}/{tag_key_name}={tag_value_name}`, `{project_id}/{tag_key_name}={tag_value_name}` | `map(string)` | `{}` | no |
159160
| resource\_usage\_export\_dataset\_id | The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export. | `string` | `""` | no |
160161
| security\_posture\_mode | Security posture mode. Accepted values are `DISABLED` and `BASIC`. Defaults to `DISABLED`. | `string` | `"DISABLED"` | no |
161162
| security\_posture\_vulnerability\_mode | Security posture vulnerability mode. Accepted values are `VULNERABILITY_DISABLED`, `VULNERABILITY_BASIC`, and `VULNERABILITY_ENTERPRISE`. Defaults to `VULNERABILITY_DISABLED`. | `string` | `"VULNERABILITY_DISABLED"` | no |

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ resource "google_container_cluster" "primary" {
185185
}
186186
}
187187
dynamic "node_pool_auto_config" {
188-
for_each = length(var.network_tags) > 0 || var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules || var.add_shadow_firewall_rules || var.insecure_kubelet_readonly_port_enabled != null || var.node_pools_cgroup_mode != null ? [1] : []
188+
for_each = length(var.network_tags) > 0 || length(var.resource_manager_tags) > 0 || var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules || var.add_shadow_firewall_rules || var.insecure_kubelet_readonly_port_enabled != null || var.node_pools_cgroup_mode != null ? [1] : []
189189
content {
190190
dynamic "network_tags" {
191191
for_each = length(var.network_tags) > 0 || var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules || var.add_shadow_firewall_rules ? [1] : []
@@ -194,6 +194,8 @@ resource "google_container_cluster" "primary" {
194194
}
195195
}
196196

197+
resource_manager_tags = length(var.resource_manager_tags) > 0 ? var.resource_manager_tags : null
198+
197199
dynamic "node_kubelet_config" {
198200
for_each = var.insecure_kubelet_readonly_port_enabled != null ? [1] : []
199201
content {

modules/beta-autopilot-private-cluster/metadata.display.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ spec:
289289
release_channel:
290290
name: release_channel
291291
title: Release Channel
292+
resource_manager_tags:
293+
name: resource_manager_tags
294+
title: Resource Manager Tags
292295
resource_usage_export_dataset_id:
293296
name: resource_usage_export_dataset_id
294297
title: Resource Usage Export Dataset Id

0 commit comments

Comments
 (0)