Skip to content

Commit a95ce1b

Browse files
richardmcsongpaulpalamarchuk
authored andcommitted
added check for optional fields
added optional field lookup and resource usage export config changed to dataset_id revert examples fixed bug where resource_usage_export_dataset_id was being set even if empty string check for null
1 parent 0fca886 commit a95ce1b

File tree

11 files changed

+53
-12
lines changed

11 files changed

+53
-12
lines changed

autogen/cluster.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ resource "google_container_cluster" "primary" {
6666
enabled = pod_security_policy_config.value.enabled
6767
}
6868
}
69-
69+
dynamic "resource_usage_export_config" {
70+
for_each = var.resource_usage_export_dataset_id != "" ? [var.resource_usage_export_dataset_id] : []
71+
content {
72+
enable_network_egress_metering = true
73+
bigquery_destination {
74+
dataset_id = resource_usage_export_dataset_id.value
75+
}
76+
}
77+
}
7078
{% endif %}
7179
dynamic "master_authorized_networks_config" {
7280
for_each = var.master_authorized_networks_config

autogen/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ locals {
102102

103103
{% if beta_cluster %}
104104
# BETA features
105-
cluster_output_istio_enabled = google_container_cluster.primary.addons_config.0.istio_config.0.disabled
106-
cluster_output_pod_security_policy_enabled = google_container_cluster.primary.pod_security_policy_config.0.enabled
105+
cluster_output_istio_enabled = google_container_cluster.primary.addons_config.0.istio_config != null ? google_container_cluster.primary.addons_config.0.istio_config.0.disabled : "true"
106+
cluster_output_pod_security_policy_enabled = google_container_cluster.primary.pod_security_policy_config != null ? google_container_cluster.primary.pod_security_policy_config.0.enabled : "false"
107107
cluster_output_intranode_visbility_enabled = google_container_cluster.primary.enable_intranode_visibility
108-
cluster_output_vertical_pod_autoscaling_enabled = google_container_cluster.primary.vertical_pod_autoscaling.0.enabled
108+
cluster_output_vertical_pod_autoscaling_enabled = google_container_cluster.primary.vertical_pod_autoscaling != null ? google_container_cluster.primary.vertical_pod_autoscaling.0.enabled : "false"
109109

110110
# /BETA features
111111
{% endif %}

autogen/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ variable "pod_security_policy_config" {
366366
}]
367367
}
368368

369+
variable "resource_usage_export_dataset_id" {
370+
description = "The dataset id for which network egress metering for this cluster will be enabled. If enabled, a daemonset will be created in the cluster to meter network egress traffic."
371+
default = ""
372+
}
373+
369374
variable "node_metadata" {
370375
description = "Specifies how node metadata is exposed to the workload running on the node"
371376
default = "UNSPECIFIED"

modules/beta-private-cluster/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
191191
| region | The region to host the cluster in (required) | string | n/a | yes |
192192
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | bool | `"true"` | no |
193193
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | bool | `"false"` | no |
194+
| resource\_usage\_export\_dataset\_id | The dataset id for which network egress metering for this cluster will be enabled. If enabled, a daemonset will be created in the cluster to meter network egress traffic. | string | `""` | no |
194195
| service\_account | The service account to run nodes as if not overridden in `node_pools`. The create_service_account variable default value (true) will cause a cluster-specific service account to be created. | string | `""` | no |
195196
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map(list(string)) | `<map>` | no |
196197
| subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes |

modules/beta-private-cluster/cluster.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ resource "google_container_cluster" "primary" {
6161
enabled = pod_security_policy_config.value.enabled
6262
}
6363
}
64-
64+
dynamic "resource_usage_export_config" {
65+
for_each = var.resource_usage_export_dataset_id != "" ? [var.resource_usage_export_dataset_id] : []
66+
content {
67+
enable_network_egress_metering = true
68+
bigquery_destination {
69+
dataset_id = resource_usage_export_dataset_id.value
70+
}
71+
}
72+
}
6573
dynamic "master_authorized_networks_config" {
6674
for_each = var.master_authorized_networks_config
6775
content {

modules/beta-private-cluster/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ locals {
9191
cluster_output_kubernetes_dashboard_enabled = google_container_cluster.primary.addons_config.0.kubernetes_dashboard.0.disabled
9292

9393
# BETA features
94-
cluster_output_istio_enabled = google_container_cluster.primary.addons_config.0.istio_config.0.disabled
95-
cluster_output_pod_security_policy_enabled = google_container_cluster.primary.pod_security_policy_config.0.enabled
94+
cluster_output_istio_enabled = google_container_cluster.primary.addons_config.0.istio_config != null ? google_container_cluster.primary.addons_config.0.istio_config.0.disabled : "true"
95+
cluster_output_pod_security_policy_enabled = google_container_cluster.primary.pod_security_policy_config != null ? google_container_cluster.primary.pod_security_policy_config.0.enabled : "false"
9696
cluster_output_intranode_visbility_enabled = google_container_cluster.primary.enable_intranode_visibility
97-
cluster_output_vertical_pod_autoscaling_enabled = google_container_cluster.primary.vertical_pod_autoscaling.0.enabled
97+
cluster_output_vertical_pod_autoscaling_enabled = google_container_cluster.primary.vertical_pod_autoscaling != null ? google_container_cluster.primary.vertical_pod_autoscaling.0.enabled : "false"
9898

9999
# /BETA features
100100

modules/beta-private-cluster/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ variable "pod_security_policy_config" {
363363
}]
364364
}
365365

366+
variable "resource_usage_export_dataset_id" {
367+
description = "The dataset id for which network egress metering for this cluster will be enabled. If enabled, a daemonset will be created in the cluster to meter network egress traffic."
368+
default = ""
369+
}
370+
366371
variable "node_metadata" {
367372
description = "Specifies how node metadata is exposed to the workload running on the node"
368373
default = "UNSPECIFIED"

modules/beta-public-cluster/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
182182
| region | The region to host the cluster in (required) | string | n/a | yes |
183183
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | bool | `"true"` | no |
184184
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | bool | `"false"` | no |
185+
| resource\_usage\_export\_dataset\_id | The dataset id for which network egress metering for this cluster will be enabled. If enabled, a daemonset will be created in the cluster to meter network egress traffic. | string | `""` | no |
185186
| service\_account | The service account to run nodes as if not overridden in `node_pools`. The create_service_account variable default value (true) will cause a cluster-specific service account to be created. | string | `""` | no |
186187
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map(list(string)) | `<map>` | no |
187188
| subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes |

modules/beta-public-cluster/cluster.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ resource "google_container_cluster" "primary" {
6161
enabled = pod_security_policy_config.value.enabled
6262
}
6363
}
64-
64+
dynamic "resource_usage_export_config" {
65+
for_each = var.resource_usage_export_dataset_id != "" ? [var.resource_usage_export_dataset_id] : []
66+
content {
67+
enable_network_egress_metering = true
68+
bigquery_destination {
69+
dataset_id = resource_usage_export_dataset_id.value
70+
}
71+
}
72+
}
6573
dynamic "master_authorized_networks_config" {
6674
for_each = var.master_authorized_networks_config
6775
content {

modules/beta-public-cluster/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ locals {
9191
cluster_output_kubernetes_dashboard_enabled = google_container_cluster.primary.addons_config.0.kubernetes_dashboard.0.disabled
9292

9393
# BETA features
94-
cluster_output_istio_enabled = google_container_cluster.primary.addons_config.0.istio_config.0.disabled
95-
cluster_output_pod_security_policy_enabled = google_container_cluster.primary.pod_security_policy_config.0.enabled
94+
cluster_output_istio_enabled = google_container_cluster.primary.addons_config.0.istio_config != null ? google_container_cluster.primary.addons_config.0.istio_config.0.disabled : "true"
95+
cluster_output_pod_security_policy_enabled = google_container_cluster.primary.pod_security_policy_config != null ? google_container_cluster.primary.pod_security_policy_config.0.enabled : "false"
9696
cluster_output_intranode_visbility_enabled = google_container_cluster.primary.enable_intranode_visibility
97-
cluster_output_vertical_pod_autoscaling_enabled = google_container_cluster.primary.vertical_pod_autoscaling.0.enabled
97+
cluster_output_vertical_pod_autoscaling_enabled = google_container_cluster.primary.vertical_pod_autoscaling != null ? google_container_cluster.primary.vertical_pod_autoscaling.0.enabled : "false"
9898

9999
# /BETA features
100100

modules/beta-public-cluster/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ variable "pod_security_policy_config" {
339339
}]
340340
}
341341

342+
variable "resource_usage_export_dataset_id" {
343+
description = "The dataset id for which network egress metering for this cluster will be enabled. If enabled, a daemonset will be created in the cluster to meter network egress traffic."
344+
default = ""
345+
}
346+
342347
variable "node_metadata" {
343348
description = "Specifies how node metadata is exposed to the workload running on the node"
344349
default = "UNSPECIFIED"

0 commit comments

Comments
 (0)