From 09711c4a993906c144b98e8b0d8381831337b9ca Mon Sep 17 00:00:00 2001 From: Saverio Proto Date: Wed, 11 Sep 2024 14:06:49 +0200 Subject: [PATCH] Add Node Labels --- README.md | 10 ++++++++++ locals.tf | 1 + main.tf | 3 +++ variables.tf | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 96ec940..e9e7eac 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,14 @@ Type: `string` Default: `null` +### [node\_labels](#input\_node\_labels) + +Description: (Optional) A map of Kubernetes labels which should be applied to nodes in this Node Pool. + +Type: `map(string)` + +Default: `{}` + ### [node\_pools](#input\_node\_pools) Description: A map of node pools that need to be created and attached on the Kubernetes cluster. The key of the map can be the name of the node pool, and the key must be static string. The value of the map is a `node_pool` block as defined below: @@ -193,6 +201,7 @@ map(object({ mode = (Optional) Should this Node Pool be used for System or User resources? Possible values are `System` and `User`. Defaults to `User`. os\_disk\_size\_gb = (Optional) The Agent Operating System disk size in GB. Changing this forces a new resource to be created. tags = (Optional) A mapping of tags to assign to the resource. At this time there's a bug in the AKS API where Tags for a Node Pool are not stored in the correct case - you [may wish to use Terraform's `ignore_changes` functionality to ignore changes to the casing](https://www.terraform.io/language/meta-arguments/lifecycle#ignore_changess) until this is fixed in the AKS API. + labels = (Optional) A map of Kubernetes labels which should be applied to nodes in this Node Pool. zones = (Optional) Specifies a list of Availability Zones in which this Kubernetes Cluster Node Pool should be located. Changing this forces a new Kubernetes Cluster Node Pool to be created. })) @@ -234,6 +243,7 @@ map(object({ mode = optional(string) os_disk_size_gb = optional(number, null) tags = optional(map(string), {}) + labels = optional(map(string), {}) zones = optional(set(string)) })) ``` diff --git a/locals.tf b/locals.tf index 9350d14..6cb2e75 100644 --- a/locals.tf +++ b/locals.tf @@ -38,6 +38,7 @@ locals { orchestrator_version = pool.orchestrator_version max_count = pool.max_count min_count = pool.min_count + labels = pool.labels os_sku = pool.os_sku zone = zone } diff --git a/main.tf b/main.tf index add2c96..a454ec8 100644 --- a/main.tf +++ b/main.tf @@ -54,6 +54,7 @@ resource "azurerm_kubernetes_cluster" "this" { max_count = 9 max_pods = 110 min_count = 3 + node_labels = var.node_labels orchestrator_version = var.orchestrator_version os_sku = "Ubuntu" tags = merge(var.tags, var.agents_tags) @@ -76,6 +77,7 @@ resource "azurerm_kubernetes_cluster" "this" { ## Resources that only support UserAssigned dynamic "identity" { for_each = local.managed_identities.user_assigned + content { type = identity.value.type identity_ids = identity.value.user_assigned_resource_ids @@ -236,6 +238,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "this" { enable_auto_scaling = true max_count = each.value.max_count min_count = each.value.min_count + node_labels = each.value.labels orchestrator_version = each.value.orchestrator_version os_sku = each.value.os_sku tags = var.tags diff --git a/variables.tf b/variables.tf index a048089..7c04631 100644 --- a/variables.tf +++ b/variables.tf @@ -99,6 +99,12 @@ variable "node_cidr" { description = "(Optional) The CIDR to use for node IPs in the Kubernetes cluster. Changing this forces a new resource to be created." } +variable "node_labels" { + type = map(string) + default = {} + description = "(Optional) A map of Kubernetes labels which should be applied to nodes in this Node Pool." +} + variable "node_pools" { type = map(object({ name = string @@ -111,6 +117,7 @@ variable "node_pools" { mode = optional(string) os_disk_size_gb = optional(number, null) tags = optional(map(string), {}) + labels = optional(map(string), {}) zones = optional(set(string)) })) default = {} @@ -126,6 +133,7 @@ map(object({ mode = (Optional) Should this Node Pool be used for System or User resources? Possible values are `System` and `User`. Defaults to `User`. os_disk_size_gb = (Optional) The Agent Operating System disk size in GB. Changing this forces a new resource to be created. tags = (Optional) A mapping of tags to assign to the resource. At this time there's a bug in the AKS API where Tags for a Node Pool are not stored in the correct case - you [may wish to use Terraform's `ignore_changes` functionality to ignore changes to the casing](https://www.terraform.io/language/meta-arguments/lifecycle#ignore_changess) until this is fixed in the AKS API. + labels = (Optional) A map of Kubernetes labels which should be applied to nodes in this Node Pool. zones = (Optional) Specifies a list of Availability Zones in which this Kubernetes Cluster Node Pool should be located. Changing this forces a new Kubernetes Cluster Node Pool to be created. }))