Skip to content

Commit 3b03c37

Browse files
committed
feat: add support for NAP/autopilot resource manager tags
1 parent 0ffe3f9 commit 3b03c37

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
@@ -233,7 +233,7 @@ Then perform the following commands on the root folder:
233233
| network\_policy | Enable network policy addon | `bool` | `false` | no |
234234
| network\_policy\_provider | The network policy provider. | `string` | `"CALICO"` | no |
235235
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
236-
| network\_tags | (Optional) - List of network tags applied to auto-provisioned node pools. | `list(string)` | `[]` | no |
236+
| network\_tags | (Optional) - List of network tags applied to autopilot and auto-provisioned node pools. | `list(string)` | `[]` | no |
237237
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA"` | no |
238238
| node\_pools | List of maps containing node pools | `list(map(any))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
239239
| 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 |
@@ -259,6 +259,7 @@ Then perform the following commands on the root folder:
259259
| 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 |
260260
| release\_channel | The release channel of this cluster. Accepted values are `UNSPECIFIED`, `RAPID`, `REGULAR` and `STABLE`. Defaults to `REGULAR`. | `string` | `"REGULAR"` | no |
261261
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | `bool` | `false` | no |
262+
| 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 |
262263
| resource\_usage\_export\_dataset\_id | The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export. | `string` | `""` | no |
263264
| security\_posture\_mode | Security posture mode. Accepted values are `DISABLED` and `BASIC`. Defaults to `DISABLED`. | `string` | `"DISABLED"` | no |
264265
| 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
@@ -394,11 +394,17 @@ variable "node_pools_oauth_scopes" {
394394
{% endif %}
395395

396396
variable "network_tags" {
397-
description = "(Optional) - List of network tags applied to auto-provisioned node pools."
397+
description = "(Optional) - List of network tags applied to autopilot and auto-provisioned node pools."
398398
type = list(string)
399399
default = []
400400
}
401401

402+
variable "resource_manager_tags" {
403+
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}\"."
404+
type = map(string)
405+
default = {}
406+
}
407+
402408
variable "enable_k8s_beta_apis" {
403409
description = "(Optional) - List of Kubernetes Beta APIs to enable in cluster."
404410
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
@@ -384,6 +384,9 @@ spec:
384384
remove_default_node_pool:
385385
name: remove_default_node_pool
386386
title: Remove Default Node Pool
387+
resource_manager_tags:
388+
name: resource_manager_tags
389+
title: Resource Manager Tags
387390
resource_usage_export_dataset_id:
388391
name: resource_usage_export_dataset_id
389392
title: Resource Usage Export Dataset Id

metadata.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,13 @@ spec:
400400
- https://www.googleapis.com/auth/cloud-platform
401401
default-node-pool: []
402402
- name: 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
varType: list(string)
405405
defaultValue: []
406+
- name: resource_manager_tags
407+
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}`"
408+
varType: map(string)
409+
defaultValue: {}
406410
- name: enable_k8s_beta_apis
407411
description: (Optional) - List of Kubernetes Beta APIs to enable in cluster.
408412
varType: list(string)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Then perform the following commands on the root folder:
143143
| name | The name of the cluster (required) | `string` | n/a | yes |
144144
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
145145
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
146-
| network\_tags | (Optional) - List of network tags applied to auto-provisioned node pools. | `list(string)` | `[]` | no |
146+
| network\_tags | (Optional) - List of network tags applied to autopilot and auto-provisioned node pools. | `list(string)` | `[]` | no |
147147
| 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 |
148148
| notification\_config\_topic | The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}. | `string` | `""` | no |
149149
| 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 |
@@ -155,6 +155,7 @@ Then perform the following commands on the root folder:
155155
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | `bool` | `true` | no |
156156
| 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 |
157157
| release\_channel | The release channel of this cluster. Accepted values are `UNSPECIFIED`, `RAPID`, `REGULAR` and `STABLE`. Defaults to `REGULAR`. | `string` | `"REGULAR"` | no |
158+
| 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 |
158159
| resource\_usage\_export\_dataset\_id | The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export. | `string` | `""` | no |
159160
| security\_posture\_mode | Security posture mode. Accepted values are `DISABLED` and `BASIC`. Defaults to `DISABLED`. | `string` | `"DISABLED"` | no |
160161
| 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
@@ -286,6 +286,9 @@ spec:
286286
release_channel:
287287
name: release_channel
288288
title: Release Channel
289+
resource_manager_tags:
290+
name: resource_manager_tags
291+
title: Resource Manager Tags
289292
resource_usage_export_dataset_id:
290293
name: resource_usage_export_dataset_id
291294
title: Resource Usage Export Dataset Id

0 commit comments

Comments
 (0)