From 10ea6081c532aa0bcd5fdd8addbb15fedfe18ee0 Mon Sep 17 00:00:00 2001 From: Zackary Maupin <5122444+zmaupin@users.noreply.github.com> Date: Mon, 21 Nov 2022 14:23:18 -0500 Subject: [PATCH] feat!: cost_management_config is out of beta now (#1470) feat: cost_management_config is out of beta now move the config outside the logic of beta only Co-authored-by: Zackary Maupin --- README.md | 1 + autogen/main/cluster.tf.tmpl | 6 +++--- autogen/main/variables.tf.tmpl | 2 -- autogen/main/versions.tf.tmpl | 2 +- cluster.tf | 8 ++++++-- docs/upgrading_to_v24.0.md | 2 +- examples/simple_regional/main.tf | 1 + modules/beta-autopilot-private-cluster/versions.tf | 2 +- modules/beta-autopilot-public-cluster/versions.tf | 2 +- modules/beta-private-cluster-update-variant/cluster.tf | 2 -- modules/beta-private-cluster-update-variant/versions.tf | 2 +- modules/beta-private-cluster/cluster.tf | 2 -- modules/beta-private-cluster/versions.tf | 2 +- modules/beta-public-cluster-update-variant/cluster.tf | 2 -- modules/beta-public-cluster-update-variant/versions.tf | 2 +- modules/beta-public-cluster/cluster.tf | 2 -- modules/beta-public-cluster/versions.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 +++++ 24 files changed, 48 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 3d777a135..de217ce12 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 1b53e0239..3abf6b0f8 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 fe8c16c30..554bbd87a 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/autogen/main/versions.tf.tmpl b/autogen/main/versions.tf.tmpl index e782845d2..48fb46a0c 100644 --- a/autogen/main/versions.tf.tmpl +++ b/autogen/main/versions.tf.tmpl @@ -24,7 +24,7 @@ terraform { required_providers { google-beta = { source = "hashicorp/google-beta" - version = ">= 4.36.0, < 5.0" + version = ">= 4.42.0, < 5.0" } kubernetes = { source = "hashicorp/kubernetes" diff --git a/cluster.tf b/cluster.tf index 172103884..8b9e80248 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/docs/upgrading_to_v24.0.md b/docs/upgrading_to_v24.0.md index 85518cd39..4e976a062 100644 --- a/docs/upgrading_to_v24.0.md +++ b/docs/upgrading_to_v24.0.md @@ -59,4 +59,4 @@ To avoid this, it is possible to edit the remote state of the `random_id` resour ### Minimum Google Provider versions -Minimum Google Provider versions have been updated to `4.36.0`. +Minimum Google Provider versions have been updated to `4.42.0`. diff --git a/examples/simple_regional/main.tf b/examples/simple_regional/main.tf index 45bdcf9cc..e5aa34859 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-autopilot-private-cluster/versions.tf b/modules/beta-autopilot-private-cluster/versions.tf index 9bfe612d8..92f3e9e88 100644 --- a/modules/beta-autopilot-private-cluster/versions.tf +++ b/modules/beta-autopilot-private-cluster/versions.tf @@ -21,7 +21,7 @@ terraform { required_providers { google-beta = { source = "hashicorp/google-beta" - version = ">= 4.36.0, < 5.0" + version = ">= 4.42.0, < 5.0" } kubernetes = { source = "hashicorp/kubernetes" diff --git a/modules/beta-autopilot-public-cluster/versions.tf b/modules/beta-autopilot-public-cluster/versions.tf index b664a8157..fd846b0c0 100644 --- a/modules/beta-autopilot-public-cluster/versions.tf +++ b/modules/beta-autopilot-public-cluster/versions.tf @@ -21,7 +21,7 @@ terraform { required_providers { google-beta = { source = "hashicorp/google-beta" - version = ">= 4.36.0, < 5.0" + version = ">= 4.42.0, < 5.0" } kubernetes = { source = "hashicorp/kubernetes" diff --git a/modules/beta-private-cluster-update-variant/cluster.tf b/modules/beta-private-cluster-update-variant/cluster.tf index 49414a852..65ad65637 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-update-variant/versions.tf b/modules/beta-private-cluster-update-variant/versions.tf index eb1e34141..7912b22b5 100644 --- a/modules/beta-private-cluster-update-variant/versions.tf +++ b/modules/beta-private-cluster-update-variant/versions.tf @@ -21,7 +21,7 @@ terraform { required_providers { google-beta = { source = "hashicorp/google-beta" - version = ">= 4.36.0, < 5.0" + version = ">= 4.42.0, < 5.0" } kubernetes = { source = "hashicorp/kubernetes" diff --git a/modules/beta-private-cluster/cluster.tf b/modules/beta-private-cluster/cluster.tf index b54bd84d1..91210d684 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-private-cluster/versions.tf b/modules/beta-private-cluster/versions.tf index 9ef1a31ae..38aa47ed2 100644 --- a/modules/beta-private-cluster/versions.tf +++ b/modules/beta-private-cluster/versions.tf @@ -21,7 +21,7 @@ terraform { required_providers { google-beta = { source = "hashicorp/google-beta" - version = ">= 4.36.0, < 5.0" + version = ">= 4.42.0, < 5.0" } kubernetes = { source = "hashicorp/kubernetes" diff --git a/modules/beta-public-cluster-update-variant/cluster.tf b/modules/beta-public-cluster-update-variant/cluster.tf index 182e52871..86ab23a8b 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-update-variant/versions.tf b/modules/beta-public-cluster-update-variant/versions.tf index 663b7cecf..d16ddac20 100644 --- a/modules/beta-public-cluster-update-variant/versions.tf +++ b/modules/beta-public-cluster-update-variant/versions.tf @@ -21,7 +21,7 @@ terraform { required_providers { google-beta = { source = "hashicorp/google-beta" - version = ">= 4.36.0, < 5.0" + version = ">= 4.42.0, < 5.0" } kubernetes = { source = "hashicorp/kubernetes" diff --git a/modules/beta-public-cluster/cluster.tf b/modules/beta-public-cluster/cluster.tf index 648303400..1d17b229e 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/beta-public-cluster/versions.tf b/modules/beta-public-cluster/versions.tf index df003c565..523b15048 100644 --- a/modules/beta-public-cluster/versions.tf +++ b/modules/beta-public-cluster/versions.tf @@ -21,7 +21,7 @@ terraform { required_providers { google-beta = { source = "hashicorp/google-beta" - version = ">= 4.36.0, < 5.0" + version = ">= 4.42.0, < 5.0" } kubernetes = { source = "hashicorp/kubernetes" diff --git a/modules/private-cluster-update-variant/README.md b/modules/private-cluster-update-variant/README.md index f0cbb86e2..9e282c002 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 a9a4da2ed..0d177c90e 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 3aedc28ce..c3d3bb511 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 e1f315471..a33638957 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 f81d5a5b0..f8dd0b8ce 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 3aedc28ce..c3d3bb511 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 f56a45caa..a69178326 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."