From a11fc2d1dfe42715957d305e6567aef16eb942cf Mon Sep 17 00:00:00 2001 From: Zackary Maupin Date: Mon, 21 Nov 2022 12:04:14 -0500 Subject: [PATCH] feat: cost_management_config is out of beta now move the config outside the logic of beta only --- README.md | 1 + autogen/main/cluster.tf.tmpl | 6 +++--- autogen/main/variables.tf.tmpl | 2 -- cluster.tf | 8 ++++++-- examples/simple_regional/main.tf | 1 + modules/beta-private-cluster-update-variant/cluster.tf | 2 -- modules/beta-private-cluster/cluster.tf | 2 -- modules/beta-public-cluster-update-variant/cluster.tf | 2 -- modules/beta-public-cluster/cluster.tf | 2 -- modules/private-cluster-update-variant/README.md | 1 + modules/private-cluster-update-variant/cluster.tf | 8 ++++++-- modules/private-cluster-update-variant/variables.tf | 5 +++++ modules/private-cluster/README.md | 1 + modules/private-cluster/cluster.tf | 8 ++++++-- modules/private-cluster/variables.tf | 5 +++++ variables.tf | 5 +++++ 16 files changed, 40 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3d777a1356..de217ce126 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ Then perform the following commands on the root folder: | disable\_legacy\_metadata\_endpoints | Disable the /0.1/ and /v1beta1/ metadata server endpoints on the node. Changing this value will cause all node pools to be recreated. | `bool` | `true` | no | | dns\_cache | The status of the NodeLocal DNSCache addon. | `bool` | `false` | no | | enable\_binary\_authorization | Enable BinAuthZ Admission controller | `bool` | `false` | no | +| enable\_cost\_allocation | Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery | `bool` | `false` | no | | enable\_network\_egress\_export | Whether to enable network egress metering for this cluster. If enabled, a daemonset will be created in the cluster to meter network egress traffic. | `bool` | `false` | no | | enable\_resource\_consumption\_export | Whether to enable resource consumption metering on this cluster. When enabled, a table will be created in the resource export BigQuery dataset to store resource consumption data. The resulting table can be joined with the resource usage table or with BigQuery billing export. | `bool` | `true` | no | | enable\_shielded\_nodes | Enable Shielded Nodes features on all nodes in this cluster | `bool` | `true` | no | diff --git a/autogen/main/cluster.tf.tmpl b/autogen/main/cluster.tf.tmpl index 1b53e02398..3abf6b0f80 100644 --- a/autogen/main/cluster.tf.tmpl +++ b/autogen/main/cluster.tf.tmpl @@ -53,13 +53,13 @@ resource "google_container_cluster" "primary" { channel = release_channel.value.channel } } -{% if beta_cluster %} dynamic "cost_management_config" { for_each = var.enable_cost_allocation ? [1] : [] content { enabled = var.enable_cost_allocation } } +{% if beta_cluster %} dynamic "confidential_nodes" { for_each = local.confidential_node_config content { @@ -598,7 +598,7 @@ resource "google_container_node_pool" "windows_pools" { for_each = local.node_pools {% else %} for_each = local.windows_node_pools - {% endif %} + {% endif %} {% if update_variant %} name = { for k, v in random_id.name : k => v.hex }[each.key] {% else %} @@ -645,7 +645,7 @@ resource "google_container_node_pool" "windows_pools" { type = lookup(placement_policy.value, "placement_policy", null) } } - + dynamic "network_config" { for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] content { diff --git a/autogen/main/variables.tf.tmpl b/autogen/main/variables.tf.tmpl index fe8c16c301..554bbd87ac 100644 --- a/autogen/main/variables.tf.tmpl +++ b/autogen/main/variables.tf.tmpl @@ -196,13 +196,11 @@ variable "node_pools_linux_node_configs_sysctls" { {% endif %} {% endif %} -{% if beta_cluster %} variable "enable_cost_allocation" { type = bool description = "Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery" default = false } -{% endif %} variable "resource_usage_export_dataset_id" { type = string description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export." diff --git a/cluster.tf b/cluster.tf index 172103884f..8b9e802489 100644 --- a/cluster.tf +++ b/cluster.tf @@ -47,6 +47,12 @@ resource "google_container_cluster" "primary" { channel = release_channel.value.channel } } + dynamic "cost_management_config" { + for_each = var.enable_cost_allocation ? [1] : [] + content { + enabled = var.enable_cost_allocation + } + } subnetwork = "projects/${local.network_project_id}/regions/${local.region}/subnetworks/${var.subnetwork}" @@ -303,7 +309,6 @@ resource "google_container_cluster" "primary" { resource "google_container_node_pool" "pools" { provider = google for_each = local.node_pools - name = each.key project = var.project_id location = local.location @@ -458,7 +463,6 @@ resource "google_container_node_pool" "pools" { resource "google_container_node_pool" "windows_pools" { provider = google for_each = local.windows_node_pools - name = each.key project = var.project_id location = local.location diff --git a/examples/simple_regional/main.tf b/examples/simple_regional/main.tf index 45bdcf9ccb..e5aa348590 100644 --- a/examples/simple_regional/main.tf +++ b/examples/simple_regional/main.tf @@ -38,6 +38,7 @@ module "gke" { ip_range_services = var.ip_range_services create_service_account = false service_account = var.compute_engine_service_account + enable_cost_allocation = true enable_binary_authorization = var.enable_binary_authorization skip_provisioners = var.skip_provisioners } diff --git a/modules/beta-private-cluster-update-variant/cluster.tf b/modules/beta-private-cluster-update-variant/cluster.tf index 49414a8526..65ad656374 100644 --- a/modules/beta-private-cluster-update-variant/cluster.tf +++ b/modules/beta-private-cluster-update-variant/cluster.tf @@ -524,7 +524,6 @@ resource "random_id" "name" { resource "google_container_node_pool" "pools" { provider = google-beta for_each = local.node_pools - name = { for k, v in random_id.name : k => v.hex }[each.key] project = var.project_id location = local.location @@ -732,7 +731,6 @@ resource "google_container_node_pool" "pools" { resource "google_container_node_pool" "windows_pools" { provider = google-beta for_each = local.windows_node_pools - name = { for k, v in random_id.name : k => v.hex }[each.key] project = var.project_id location = local.location diff --git a/modules/beta-private-cluster/cluster.tf b/modules/beta-private-cluster/cluster.tf index b54bd84d1a..91210d6847 100644 --- a/modules/beta-private-cluster/cluster.tf +++ b/modules/beta-private-cluster/cluster.tf @@ -430,7 +430,6 @@ resource "google_container_cluster" "primary" { resource "google_container_node_pool" "pools" { provider = google-beta for_each = local.node_pools - name = each.key project = var.project_id location = local.location @@ -637,7 +636,6 @@ resource "google_container_node_pool" "pools" { resource "google_container_node_pool" "windows_pools" { provider = google-beta for_each = local.windows_node_pools - name = each.key project = var.project_id location = local.location diff --git a/modules/beta-public-cluster-update-variant/cluster.tf b/modules/beta-public-cluster-update-variant/cluster.tf index 182e528719..86ab23a8bf 100644 --- a/modules/beta-public-cluster-update-variant/cluster.tf +++ b/modules/beta-public-cluster-update-variant/cluster.tf @@ -505,7 +505,6 @@ resource "random_id" "name" { resource "google_container_node_pool" "pools" { provider = google-beta for_each = local.node_pools - name = { for k, v in random_id.name : k => v.hex }[each.key] project = var.project_id location = local.location @@ -713,7 +712,6 @@ resource "google_container_node_pool" "pools" { resource "google_container_node_pool" "windows_pools" { provider = google-beta for_each = local.windows_node_pools - name = { for k, v in random_id.name : k => v.hex }[each.key] project = var.project_id location = local.location diff --git a/modules/beta-public-cluster/cluster.tf b/modules/beta-public-cluster/cluster.tf index 6483034001..1d17b229ed 100644 --- a/modules/beta-public-cluster/cluster.tf +++ b/modules/beta-public-cluster/cluster.tf @@ -411,7 +411,6 @@ resource "google_container_cluster" "primary" { resource "google_container_node_pool" "pools" { provider = google-beta for_each = local.node_pools - name = each.key project = var.project_id location = local.location @@ -618,7 +617,6 @@ resource "google_container_node_pool" "pools" { resource "google_container_node_pool" "windows_pools" { provider = google-beta for_each = local.windows_node_pools - name = each.key project = var.project_id location = local.location diff --git a/modules/private-cluster-update-variant/README.md b/modules/private-cluster-update-variant/README.md index f0cbb86e26..9e282c0021 100644 --- a/modules/private-cluster-update-variant/README.md +++ b/modules/private-cluster-update-variant/README.md @@ -176,6 +176,7 @@ Then perform the following commands on the root folder: | disable\_legacy\_metadata\_endpoints | Disable the /0.1/ and /v1beta1/ metadata server endpoints on the node. Changing this value will cause all node pools to be recreated. | `bool` | `true` | no | | dns\_cache | The status of the NodeLocal DNSCache addon. | `bool` | `false` | no | | enable\_binary\_authorization | Enable BinAuthZ Admission controller | `bool` | `false` | no | +| enable\_cost\_allocation | Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery | `bool` | `false` | no | | enable\_network\_egress\_export | Whether to enable network egress metering for this cluster. If enabled, a daemonset will be created in the cluster to meter network egress traffic. | `bool` | `false` | no | | enable\_private\_endpoint | (Beta) Whether the master's internal IP address is used as the cluster endpoint | `bool` | `false` | no | | enable\_private\_nodes | (Beta) Whether nodes have internal IP addresses only | `bool` | `false` | no | diff --git a/modules/private-cluster-update-variant/cluster.tf b/modules/private-cluster-update-variant/cluster.tf index a9a4da2edd..0d177c90ef 100644 --- a/modules/private-cluster-update-variant/cluster.tf +++ b/modules/private-cluster-update-variant/cluster.tf @@ -47,6 +47,12 @@ resource "google_container_cluster" "primary" { channel = release_channel.value.channel } } + dynamic "cost_management_config" { + for_each = var.enable_cost_allocation ? [1] : [] + content { + enabled = var.enable_cost_allocation + } + } subnetwork = "projects/${local.network_project_id}/regions/${local.region}/subnetworks/${var.subnetwork}" @@ -416,7 +422,6 @@ resource "random_id" "name" { resource "google_container_node_pool" "pools" { provider = google for_each = local.node_pools - name = { for k, v in random_id.name : k => v.hex }[each.key] project = var.project_id location = local.location @@ -572,7 +577,6 @@ resource "google_container_node_pool" "pools" { resource "google_container_node_pool" "windows_pools" { provider = google for_each = local.windows_node_pools - name = { for k, v in random_id.name : k => v.hex }[each.key] project = var.project_id location = local.location diff --git a/modules/private-cluster-update-variant/variables.tf b/modules/private-cluster-update-variant/variables.tf index 3aedc28ce8..c3d3bb511d 100644 --- a/modules/private-cluster-update-variant/variables.tf +++ b/modules/private-cluster-update-variant/variables.tf @@ -181,6 +181,11 @@ variable "node_pools_metadata" { } } +variable "enable_cost_allocation" { + type = bool + description = "Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery" + default = false +} variable "resource_usage_export_dataset_id" { type = string description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export." diff --git a/modules/private-cluster/README.md b/modules/private-cluster/README.md index e1f3154716..a336389570 100644 --- a/modules/private-cluster/README.md +++ b/modules/private-cluster/README.md @@ -154,6 +154,7 @@ Then perform the following commands on the root folder: | disable\_legacy\_metadata\_endpoints | Disable the /0.1/ and /v1beta1/ metadata server endpoints on the node. Changing this value will cause all node pools to be recreated. | `bool` | `true` | no | | dns\_cache | The status of the NodeLocal DNSCache addon. | `bool` | `false` | no | | enable\_binary\_authorization | Enable BinAuthZ Admission controller | `bool` | `false` | no | +| enable\_cost\_allocation | Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery | `bool` | `false` | no | | enable\_network\_egress\_export | Whether to enable network egress metering for this cluster. If enabled, a daemonset will be created in the cluster to meter network egress traffic. | `bool` | `false` | no | | enable\_private\_endpoint | (Beta) Whether the master's internal IP address is used as the cluster endpoint | `bool` | `false` | no | | enable\_private\_nodes | (Beta) Whether nodes have internal IP addresses only | `bool` | `false` | no | diff --git a/modules/private-cluster/cluster.tf b/modules/private-cluster/cluster.tf index f81d5a5b03..f8dd0b8cee 100644 --- a/modules/private-cluster/cluster.tf +++ b/modules/private-cluster/cluster.tf @@ -47,6 +47,12 @@ resource "google_container_cluster" "primary" { channel = release_channel.value.channel } } + dynamic "cost_management_config" { + for_each = var.enable_cost_allocation ? [1] : [] + content { + enabled = var.enable_cost_allocation + } + } subnetwork = "projects/${local.network_project_id}/regions/${local.region}/subnetworks/${var.subnetwork}" @@ -322,7 +328,6 @@ resource "google_container_cluster" "primary" { resource "google_container_node_pool" "pools" { provider = google for_each = local.node_pools - name = each.key project = var.project_id location = local.location @@ -477,7 +482,6 @@ resource "google_container_node_pool" "pools" { resource "google_container_node_pool" "windows_pools" { provider = google for_each = local.windows_node_pools - name = each.key project = var.project_id location = local.location diff --git a/modules/private-cluster/variables.tf b/modules/private-cluster/variables.tf index 3aedc28ce8..c3d3bb511d 100644 --- a/modules/private-cluster/variables.tf +++ b/modules/private-cluster/variables.tf @@ -181,6 +181,11 @@ variable "node_pools_metadata" { } } +variable "enable_cost_allocation" { + type = bool + description = "Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery" + default = false +} variable "resource_usage_export_dataset_id" { type = string description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export." diff --git a/variables.tf b/variables.tf index f56a45caa5..a691783262 100644 --- a/variables.tf +++ b/variables.tf @@ -181,6 +181,11 @@ variable "node_pools_metadata" { } } +variable "enable_cost_allocation" { + type = bool + description = "Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery" + default = false +} variable "resource_usage_export_dataset_id" { type = string description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export."