Skip to content

Commit

Permalink
fix: add node_pool_taints to all the modules
Browse files Browse the repository at this point in the history
  • Loading branch information
marko7460 committed Oct 8, 2020
1 parent f31b1f4 commit 0ed6ed0
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Then perform the following commands on the root folder:
| node\_pools\_metadata | Map of maps containing node metadata by node-pool name | map(map(string)) | `<map>` | no |
| node\_pools\_oauth\_scopes | Map of lists containing node oauth scopes by node-pool name | map(list(string)) | `<map>` | no |
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | map(list(string)) | `<map>` | no |
| node\_pools\_taints | Map of lists containing node taints by node-pool name | object | `<map>` | no |
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | list(string) | `<list>` | no |
| project\_id | The project ID to host the cluster in (required) | string | n/a | yes |
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | string | `"null"` | no |
Expand Down
2 changes: 0 additions & 2 deletions autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ resource "google_container_node_pool" "pools" {
"disable-legacy-endpoints" = var.disable_legacy_metadata_endpoints
},
)
{% if beta_cluster %}
dynamic "taint" {
for_each = concat(
local.node_pools_taints["all"],
Expand All @@ -470,7 +469,6 @@ resource "google_container_node_pool" "pools" {
value = taint.value.value
}
}
{% endif %}
tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-${each.value["name"]}"] : [],
Expand Down
2 changes: 1 addition & 1 deletion autogen/main/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ variable "cluster_autoscaling" {
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}
{% endif %}

variable "node_pools_taints" {
type = map(list(object({ key = string, value = string, effect = string })))
Expand All @@ -239,7 +240,6 @@ variable "node_pools_taints" {
}
}

{% endif %}
variable "node_pools_tags" {
type = map(list(string))
description = "Map of lists containing node network tags by node-pool name"
Expand Down
2 changes: 0 additions & 2 deletions autogen/main/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ locals {
var.node_pools_metadata
)

{% if beta_cluster %}
node_pools_taints = merge(
{ all = [] },
{ default-node-pool = [] },
Expand All @@ -51,7 +50,6 @@ locals {
var.node_pools_taints
)

{% endif %}
node_pools_tags = merge(
{ all = [] },
{ default-node-pool = [] },
Expand Down
11 changes: 11 additions & 0 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ resource "google_container_node_pool" "pools" {
"disable-legacy-endpoints" = var.disable_legacy_metadata_endpoints
},
)
dynamic "taint" {
for_each = concat(
local.node_pools_taints["all"],
local.node_pools_taints[each.value["name"]],
)
content {
effect = taint.value.effect
key = taint.value.key
value = taint.value.value
}
}
tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-${each.value["name"]}"] : [],
Expand Down
1 change: 1 addition & 0 deletions modules/private-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ Then perform the following commands on the root folder:
| node\_pools\_metadata | Map of maps containing node metadata by node-pool name | map(map(string)) | `<map>` | no |
| node\_pools\_oauth\_scopes | Map of lists containing node oauth scopes by node-pool name | map(list(string)) | `<map>` | no |
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | map(list(string)) | `<map>` | no |
| node\_pools\_taints | Map of lists containing node taints by node-pool name | object | `<map>` | no |
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | list(string) | `<list>` | no |
| project\_id | The project ID to host the cluster in (required) | string | n/a | yes |
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | string | `"null"` | no |
Expand Down
11 changes: 11 additions & 0 deletions modules/private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ resource "google_container_node_pool" "pools" {
"disable-legacy-endpoints" = var.disable_legacy_metadata_endpoints
},
)
dynamic "taint" {
for_each = concat(
local.node_pools_taints["all"],
local.node_pools_taints[each.value["name"]],
)
content {
effect = taint.value.effect
key = taint.value.key
value = taint.value.value
}
}
tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-${each.value["name"]}"] : [],
Expand Down
12 changes: 12 additions & 0 deletions modules/private-cluster-update-variant/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ variable "enable_resource_consumption_export" {
description = "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."
default = true
}

variable "node_pools_taints" {
type = map(list(object({ key = string, value = string, effect = string })))
description = "Map of lists containing node taints by node-pool name"

# Default is being set in variables_defaults.tf
default = {
all = []
default-node-pool = []
}
}

variable "node_pools_tags" {
type = map(list(string))
description = "Map of lists containing node network tags by node-pool name"
Expand Down
10 changes: 10 additions & 0 deletions modules/private-cluster-update-variant/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ locals {
var.node_pools_metadata
)

node_pools_taints = merge(
{ all = [] },
{ default-node-pool = [] },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : []]
),
var.node_pools_taints
)

node_pools_tags = merge(
{ all = [] },
{ default-node-pool = [] },
Expand Down
1 change: 1 addition & 0 deletions modules/private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Then perform the following commands on the root folder:
| node\_pools\_metadata | Map of maps containing node metadata by node-pool name | map(map(string)) | `<map>` | no |
| node\_pools\_oauth\_scopes | Map of lists containing node oauth scopes by node-pool name | map(list(string)) | `<map>` | no |
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | map(list(string)) | `<map>` | no |
| node\_pools\_taints | Map of lists containing node taints by node-pool name | object | `<map>` | no |
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | list(string) | `<list>` | no |
| project\_id | The project ID to host the cluster in (required) | string | n/a | yes |
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | string | `"null"` | no |
Expand Down
11 changes: 11 additions & 0 deletions modules/private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ resource "google_container_node_pool" "pools" {
"disable-legacy-endpoints" = var.disable_legacy_metadata_endpoints
},
)
dynamic "taint" {
for_each = concat(
local.node_pools_taints["all"],
local.node_pools_taints[each.value["name"]],
)
content {
effect = taint.value.effect
key = taint.value.key
value = taint.value.value
}
}
tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-${each.value["name"]}"] : [],
Expand Down
12 changes: 12 additions & 0 deletions modules/private-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ variable "enable_resource_consumption_export" {
description = "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."
default = true
}

variable "node_pools_taints" {
type = map(list(object({ key = string, value = string, effect = string })))
description = "Map of lists containing node taints by node-pool name"

# Default is being set in variables_defaults.tf
default = {
all = []
default-node-pool = []
}
}

variable "node_pools_tags" {
type = map(list(string))
description = "Map of lists containing node network tags by node-pool name"
Expand Down
10 changes: 10 additions & 0 deletions modules/private-cluster/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ locals {
var.node_pools_metadata
)

node_pools_taints = merge(
{ all = [] },
{ default-node-pool = [] },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : []]
),
var.node_pools_taints
)

node_pools_tags = merge(
{ all = [] },
{ default-node-pool = [] },
Expand Down
6 changes: 5 additions & 1 deletion test/setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ resource "random_id" "random_project_id_suffix" {

module "gke-project-1" {
source = "terraform-google-modules/project-factory/google"
version = "~> 8.0"
version = "~> 9.1.0"

name = "ci-gke-${random_id.random_project_id_suffix.hex}"
random_project_id = true
Expand All @@ -39,6 +39,10 @@ module "gke-project-1" {
"serviceusage.googleapis.com",
"storage-api.googleapis.com",
]
activate_api_identities = [{
api = "container.googleapis.com"
roles = ["roles/cloudkms.cryptoKeyEncrypterDecrypter"]
}]
}

module "gke-project-2" {
Expand Down
4 changes: 2 additions & 2 deletions test/setup/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ terraform {
}

provider "google" {
version = "3.25.0"
version = "3.42.0"
}

provider "google-beta" {
version = "3.32.0"
version = "3.42.0"
}
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ variable "enable_resource_consumption_export" {
description = "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."
default = true
}

variable "node_pools_taints" {
type = map(list(object({ key = string, value = string, effect = string })))
description = "Map of lists containing node taints by node-pool name"

# Default is being set in variables_defaults.tf
default = {
all = []
default-node-pool = []
}
}

variable "node_pools_tags" {
type = map(list(string))
description = "Map of lists containing node network tags by node-pool name"
Expand Down
10 changes: 10 additions & 0 deletions variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ locals {
var.node_pools_metadata
)

node_pools_taints = merge(
{ all = [] },
{ default-node-pool = [] },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : []]
),
var.node_pools_taints
)

node_pools_tags = merge(
{ all = [] },
{ default-node-pool = [] },
Expand Down

0 comments on commit 0ed6ed0

Please sign in to comment.