From 0c07c4d456fbbbd76dceede20279d73379a2c0d8 Mon Sep 17 00:00:00 2001 From: Eric Malloy Date: Wed, 13 Feb 2019 15:47:18 -0500 Subject: [PATCH 1/6] introduce cluster_resource_labels map var add resource_labels param to cluster_regional and zonal resource templates +squash, commit changes from 40d77b71cce074e8ba7ee0a9dc8d53671ea328a2 via make generate best practice +squash - empty map var commit formatting changes from make generate --- autogen/cluster_regional.tf | 1 + autogen/cluster_zonal.tf | 1 + autogen/variables.tf | 8 ++++++++ cluster_regional.tf | 1 + cluster_zonal.tf | 1 + modules/private-cluster/cluster_regional.tf | 1 + modules/private-cluster/cluster_zonal.tf | 1 + modules/private-cluster/outputs.tf | 2 +- modules/private-cluster/variables.tf | 8 ++++++++ outputs.tf | 2 +- variables.tf | 8 ++++++++ 11 files changed, 32 insertions(+), 2 deletions(-) diff --git a/autogen/cluster_regional.tf b/autogen/cluster_regional.tf index cf1c427b5f..d158977711 100644 --- a/autogen/cluster_regional.tf +++ b/autogen/cluster_regional.tf @@ -25,6 +25,7 @@ resource "google_container_cluster" "primary" { name = "${var.name}" description = "${var.description}" project = "${var.project_id}" + resource_labels = "${var.cluster_resource_labels}" region = "${var.region}" additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"] diff --git a/autogen/cluster_zonal.tf b/autogen/cluster_zonal.tf index d56191b222..7c7fc616aa 100644 --- a/autogen/cluster_zonal.tf +++ b/autogen/cluster_zonal.tf @@ -25,6 +25,7 @@ resource "google_container_cluster" "zonal_primary" { name = "${var.name}" description = "${var.description}" project = "${var.project_id}" + resource_labels = "${var.cluster_resource_labels}" zone = "${var.zones[0]}" additional_zones = ["${slice(var.zones,1,length(var.zones))}"] diff --git a/autogen/variables.tf b/autogen/variables.tf index 7636039b49..6b8771dd24 100644 --- a/autogen/variables.tf +++ b/autogen/variables.tf @@ -29,6 +29,14 @@ variable "description" { default = "" } +variable "cluster_resource_labels" { + type = "map" + description = "Map containing cluster labels. Maximum of 64 labels" + + default = { + } +} + variable "regional" { description = "Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!)" default = true diff --git a/cluster_regional.tf b/cluster_regional.tf index 2446483943..8c105daea8 100644 --- a/cluster_regional.tf +++ b/cluster_regional.tf @@ -25,6 +25,7 @@ resource "google_container_cluster" "primary" { name = "${var.name}" description = "${var.description}" project = "${var.project_id}" + resource_labels = "${var.cluster_resource_labels}" region = "${var.region}" additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"] diff --git a/cluster_zonal.tf b/cluster_zonal.tf index 10b8b6a3f8..b2a5057663 100644 --- a/cluster_zonal.tf +++ b/cluster_zonal.tf @@ -25,6 +25,7 @@ resource "google_container_cluster" "zonal_primary" { name = "${var.name}" description = "${var.description}" project = "${var.project_id}" + resource_labels = "${var.cluster_resource_labels}" zone = "${var.zones[0]}" additional_zones = ["${slice(var.zones,1,length(var.zones))}"] diff --git a/modules/private-cluster/cluster_regional.tf b/modules/private-cluster/cluster_regional.tf index 08f960f9d3..fa8bfc5869 100644 --- a/modules/private-cluster/cluster_regional.tf +++ b/modules/private-cluster/cluster_regional.tf @@ -25,6 +25,7 @@ resource "google_container_cluster" "primary" { name = "${var.name}" description = "${var.description}" project = "${var.project_id}" + resource_labels = "${var.cluster_resource_labels}" region = "${var.region}" additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"] diff --git a/modules/private-cluster/cluster_zonal.tf b/modules/private-cluster/cluster_zonal.tf index 4675f5d6aa..f889dd2fe8 100644 --- a/modules/private-cluster/cluster_zonal.tf +++ b/modules/private-cluster/cluster_zonal.tf @@ -25,6 +25,7 @@ resource "google_container_cluster" "zonal_primary" { name = "${var.name}" description = "${var.description}" project = "${var.project_id}" + resource_labels = "${var.cluster_resource_labels}" zone = "${var.zones[0]}" additional_zones = ["${slice(var.zones,1,length(var.zones))}"] diff --git a/modules/private-cluster/outputs.tf b/modules/private-cluster/outputs.tf index 455f69790a..550a6f99b0 100644 --- a/modules/private-cluster/outputs.tf +++ b/modules/private-cluster/outputs.tf @@ -111,4 +111,4 @@ output "node_pools_versions" { output "service_account" { description = "The service account to default running nodes as if not overridden in `node_pools`." value = "${local.service_account}" -} \ No newline at end of file +} diff --git a/modules/private-cluster/variables.tf b/modules/private-cluster/variables.tf index 2bc5ca2543..9b3e68594f 100644 --- a/modules/private-cluster/variables.tf +++ b/modules/private-cluster/variables.tf @@ -29,6 +29,14 @@ variable "description" { default = "" } +variable "cluster_resource_labels" { + type = "map" + description = "Map containing cluster labels. Maximum of 64 labels" + + default = { + } +} + variable "regional" { description = "Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!)" default = true diff --git a/outputs.tf b/outputs.tf index 455f69790a..550a6f99b0 100644 --- a/outputs.tf +++ b/outputs.tf @@ -111,4 +111,4 @@ output "node_pools_versions" { output "service_account" { description = "The service account to default running nodes as if not overridden in `node_pools`." value = "${local.service_account}" -} \ No newline at end of file +} diff --git a/variables.tf b/variables.tf index 3582e5a55e..6e62a7dde5 100644 --- a/variables.tf +++ b/variables.tf @@ -29,6 +29,14 @@ variable "description" { default = "" } +variable "cluster_resource_labels" { + type = "map" + description = "Map containing cluster labels. Maximum of 64 labels" + + default = { + } +} + variable "regional" { description = "Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!)" default = true From 94aa66ef91bb7caafb55108a666d0ead54fa0eb3 Mon Sep 17 00:00:00 2001 From: Eric Malloy Date: Fri, 1 Mar 2019 11:41:34 -0500 Subject: [PATCH 2/6] add cluster_resource_labels var to example instantiations --- examples/simple_regional/variables.tf | 9 +++++++++ examples/simple_regional_private/variables.tf | 9 +++++++++ examples/simple_zonal/variables.tf | 9 +++++++++ examples/simple_zonal_private/variables.tf | 9 +++++++++ 4 files changed, 36 insertions(+) diff --git a/examples/simple_regional/variables.tf b/examples/simple_regional/variables.tf index 8501b205b3..1df64d97c6 100644 --- a/examples/simple_regional/variables.tf +++ b/examples/simple_regional/variables.tf @@ -50,3 +50,12 @@ variable "ip_range_services" { variable "compute_engine_service_account" { description = "Service account to associate to the nodes in the cluster" } + +variable "cluster_resource_labels" { + type = "map" + description = "Map containing cluster labels. Maximum of 64 labels" + + default = { + } + +} diff --git a/examples/simple_regional_private/variables.tf b/examples/simple_regional_private/variables.tf index 8501b205b3..695ae4d7fd 100644 --- a/examples/simple_regional_private/variables.tf +++ b/examples/simple_regional_private/variables.tf @@ -50,3 +50,12 @@ variable "ip_range_services" { variable "compute_engine_service_account" { description = "Service account to associate to the nodes in the cluster" } + +variable "cluster_resource_labels" { + type = "map" + description = "Map containing cluster labels. Maximum of 64 labels" + + default = { + } + +} \ No newline at end of file diff --git a/examples/simple_zonal/variables.tf b/examples/simple_zonal/variables.tf index 10130ab2d1..0a7efc7944 100644 --- a/examples/simple_zonal/variables.tf +++ b/examples/simple_zonal/variables.tf @@ -51,3 +51,12 @@ variable "ip_range_pods" { variable "ip_range_services" { description = "The secondary ip range to use for pods" } + +variable "cluster_resource_labels" { + type = "map" + description = "Map containing cluster labels. Maximum of 64 labels" + + default = { + } + +} \ No newline at end of file diff --git a/examples/simple_zonal_private/variables.tf b/examples/simple_zonal_private/variables.tf index ebb151e38a..3e802bc2d4 100644 --- a/examples/simple_zonal_private/variables.tf +++ b/examples/simple_zonal_private/variables.tf @@ -55,3 +55,12 @@ variable "ip_range_services" { variable "compute_engine_service_account" { description = "Service account to associate to the nodes in the cluster" } + +variable "cluster_resource_labels" { + type = "map" + description = "Map containing cluster labels. Maximum of 64 labels" + + default = { + } + +} From 9465170f23be14004e0c503748b69bb83312f7db Mon Sep 17 00:00:00 2001 From: Eric Malloy Date: Fri, 1 Mar 2019 11:50:32 -0500 Subject: [PATCH 3/6] update docs --- README.md | 2 ++ examples/simple_regional_private/README.md | 1 + examples/simple_zonal/README.md | 1 + examples/simple_zonal_private/README.md | 1 + modules/private-cluster/README.md | 1 + 5 files changed, 6 insertions(+) diff --git a/README.md b/README.md index adbd19d3d8..6ef7b491d2 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ Then perform the following commands on the root folder: | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| +<<<<<<< HEAD | description | The description of the cluster | string | `""` | no | | horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | string | `"true"` | no | | http\_load\_balancing | Enable httpload balancer addon | string | `"true"` | no | @@ -127,6 +128,7 @@ Then perform the following commands on the root folder: | service\_account | The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account | string | `""` | no | | stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map | `` | no | | subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes | +| cluster_resource_labels | Map containing cluster labels. Maximum of 64 labels | map | `` | no | | zones | The zones to host the cluster in (optional if regional cluster / required if zonal) | list | `` | no | ## Outputs diff --git a/examples/simple_regional_private/README.md b/examples/simple_regional_private/README.md index f2b5d21f2e..702480e47e 100644 --- a/examples/simple_regional_private/README.md +++ b/examples/simple_regional_private/README.md @@ -17,6 +17,7 @@ This example illustrates how to create a simple private cluster. | project\_id | The project ID to host the cluster in | string | n/a | yes | | region | The region to host the cluster in | string | n/a | yes | | subnetwork | The subnetwork to host the cluster in | string | n/a | yes | +| cluster_resource_labels | Map containing cluster labels. Maximum of 64 labels | map | `` | no | ## Outputs diff --git a/examples/simple_zonal/README.md b/examples/simple_zonal/README.md index 0f093c7f51..f722361607 100644 --- a/examples/simple_zonal/README.md +++ b/examples/simple_zonal/README.md @@ -17,6 +17,7 @@ This example illustrates how to create a simple cluster. | region | The region to host the cluster in | string | n/a | yes | | subnetwork | The subnetwork to host the cluster in | string | n/a | yes | | zones | The zone to host the cluster in (required if is a zonal cluster) | list | n/a | yes | +| cluster_name_suffix | A suffix to append to the default cluster name | string | `` | no | ## Outputs diff --git a/examples/simple_zonal_private/README.md b/examples/simple_zonal_private/README.md index a82ec3d943..ec03023c92 100644 --- a/examples/simple_zonal_private/README.md +++ b/examples/simple_zonal_private/README.md @@ -18,6 +18,7 @@ This example illustrates how to create a simple private cluster. | region | The region to host the cluster in | string | n/a | yes | | subnetwork | The subnetwork to host the cluster in | string | n/a | yes | | zones | The zone to host the cluster in (required if is a zonal cluster) | list | n/a | yes | +| cluster_name_suffix | A suffix to append to the default cluster name | string | `` | no | ## Outputs diff --git a/modules/private-cluster/README.md b/modules/private-cluster/README.md index 5e9897c8a4..5cb7c5a615 100644 --- a/modules/private-cluster/README.md +++ b/modules/private-cluster/README.md @@ -133,6 +133,7 @@ Then perform the following commands on the root folder: | service\_account | The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account | string | `""` | no | | stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map | `` | no | | subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes | +| cluster_resource_labels | Map containing cluster labels. Maximum of 64 labels | map | `` | no | | zones | The zones to host the cluster in (optional if regional cluster / required if zonal) | list | `` | no | ## Outputs From 44d5be2219347390d10270c51b1036f850189bdc Mon Sep 17 00:00:00 2001 From: Eric Malloy Date: Mon, 25 Mar 2019 15:23:33 -0400 Subject: [PATCH 4/6] add CLUSTER_RESOURCE_LABELS and value to ci tests --- examples/simple_regional/variables.tf | 1 + test/ci/simple-regional.yml | 1 + test/ci_integration.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/examples/simple_regional/variables.tf b/examples/simple_regional/variables.tf index 1df64d97c6..fa38ba709b 100644 --- a/examples/simple_regional/variables.tf +++ b/examples/simple_regional/variables.tf @@ -56,6 +56,7 @@ variable "cluster_resource_labels" { description = "Map containing cluster labels. Maximum of 64 labels" default = { + created-by = "terraform" } } diff --git a/test/ci/simple-regional.yml b/test/ci/simple-regional.yml index a3bec48292..8ea7345e88 100644 --- a/test/ci/simple-regional.yml +++ b/test/ci/simple-regional.yml @@ -16,3 +16,4 @@ params: COMPUTE_ENGINE_SERVICE_ACCOUNT: "" REGION: "us-east4" ZONES: '["us-east4-a", "us-east4-b", "us-east4-c"]' + CLUSTER_RESOURCE_LABELS: 'cluster_resource_labels={ created-by = "terraform" }' diff --git a/test/ci_integration.sh b/test/ci_integration.sh index ba92fd5558..9da29293f0 100755 --- a/test/ci_integration.sh +++ b/test/ci_integration.sh @@ -43,6 +43,7 @@ setup_environment() { export TF_VAR_credentials_path_relative="../shared/credentials.json" export TF_VAR_region="$REGION" export TF_VAR_zones="$ZONES" + export TF_VAR_cluster_resource_labels="$CLUSTER_RESOURCE_LABELS" export TF_VAR_compute_engine_service_account="$COMPUTE_ENGINE_SERVICE_ACCOUNT" } From e5dffcf2905b70c7be2dfeebf30bb179d31894f7 Mon Sep 17 00:00:00 2001 From: Eric Malloy Date: Mon, 25 Mar 2019 22:20:42 -0400 Subject: [PATCH 5/6] test assertion for presence of cluster label defined in fixture --- test/integration/simple_regional/controls/gcloud.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/integration/simple_regional/controls/gcloud.rb b/test/integration/simple_regional/controls/gcloud.rb index 83f33be1c3..1108a1d3c9 100644 --- a/test/integration/simple_regional/controls/gcloud.rb +++ b/test/integration/simple_regional/controls/gcloud.rb @@ -58,6 +58,12 @@ }, }) end + + it "has cluster resource labels" do + expect(data['resourceLabels']).to eq({ + "created-by" => "terraform", + }) + end end describe "default node pool" do @@ -138,6 +144,10 @@ ) end + + + + it "has the expected network tags" do expect(node_pools).to include( including( From 857c04d64c0b773d808ee4b639a5950d7ee748b0 Mon Sep 17 00:00:00 2001 From: Eric Malloy Date: Mon, 25 Mar 2019 22:23:50 -0400 Subject: [PATCH 6/6] statically provide map value for fixture --- test/fixtures/shared/variables.tf | 5 +++++ test/fixtures/simple_regional/example.tf | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/test/fixtures/shared/variables.tf b/test/fixtures/shared/variables.tf index 8955c2e0be..dc91b5b0a4 100644 --- a/test/fixtures/shared/variables.tf +++ b/test/fixtures/shared/variables.tf @@ -35,3 +35,8 @@ variable "zones" { variable "compute_engine_service_account" { description = "The email address of the service account to associate with the GKE cluster" } + +variable "cluster_resource_labels" { + type = "map" + description = "Map containing cluster labels. Maximum of 64 labels" +} diff --git a/test/fixtures/simple_regional/example.tf b/test/fixtures/simple_regional/example.tf index 3f0855d225..ca0eb22523 100644 --- a/test/fixtures/simple_regional/example.tf +++ b/test/fixtures/simple_regional/example.tf @@ -26,4 +26,8 @@ module "example" { ip_range_pods = "${google_compute_subnetwork.main.secondary_ip_range.0.range_name}" ip_range_services = "${google_compute_subnetwork.main.secondary_ip_range.1.range_name}" compute_engine_service_account = "${var.compute_engine_service_account}" + + cluster_resource_labels = { + created-by = "terraform" + } }