From fc552456ada0567de8c4d361003baf78cb20d243 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Fri, 14 Oct 2022 19:47:52 +0200 Subject: [PATCH] Add: additional node pools submodule Signed-off-by: Nicolas Lamirault --- modules/node-pools/data.tf | 4 ++++ modules/node-pools/main.tf | 37 +++++++++++++++++++++++++++++++++ modules/node-pools/outputs.tf | 0 modules/node-pools/variables.tf | 15 +++++++++++++ modules/node-pools/versions.tf | 14 +++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 modules/node-pools/data.tf create mode 100644 modules/node-pools/main.tf create mode 100644 modules/node-pools/outputs.tf create mode 100644 modules/node-pools/variables.tf create mode 100644 modules/node-pools/versions.tf diff --git a/modules/node-pools/data.tf b/modules/node-pools/data.tf new file mode 100644 index 00000000..150587cf --- /dev/null +++ b/modules/node-pools/data.tf @@ -0,0 +1,4 @@ +data "azurerm_kubernetes_cluster" "main" { + name = var.cluster_name + resource_group_name = var.resource_group_name +} \ No newline at end of file diff --git a/modules/node-pools/main.tf b/modules/node-pools/main.tf new file mode 100644 index 00000000..a9f65203 --- /dev/null +++ b/modules/node-pools/main.tf @@ -0,0 +1,37 @@ +resource "azurerm_kubernetes_cluster_node_pool" "workers" { + for_each = var.additional_node_pools + + name = each.value["name"] + kubernetes_cluster_id = data.azurerm_kubernetes_cluster.main.id + vm_size = each.value["vm_size"] + + enable_auto_scaling = lookup(each.value, "enable_auto_scaling", false) + enable_host_encryption = lookup(each.value, "enable_host_encryption", false) + enable_node_public_ip = lookup(each.value, "enable_node_public_ip", false) + eviction_policy = lookup(each.value, "priority", "Regular") == "Spot" ? lookup(each.value, "eviction_policy", "Delete") : null + fips_enabled = lookup(each.value, "fips_enabled", false) + kubelet_disk_type = lookup(each.value, "kubelet_disk_type", null) + max_pods = lookup(each.value, "max_pods", null) + mode = lookup(each.value, "mode", "User") + node_labels = lookup(each.value, "node_labels", null) + node_public_ip_prefix_id = lookup(each.value, "enable_node_public_ip", false) == true ? lookup(each.value, "node_public_ip_prefix_id", null) : null + node_taints = lookup(each.value, "node_taints", []) + orchestrator_version = lookup(each.value, "orchestrator_version", null) + os_disk_size_gb = lookup(each.value, "os_disk_size_gb", null) + os_disk_type = lookup(each.value, "os_disk_type", "Managed") + pod_subnet_id = lookup(each.value, "pod_subnet_id", null) + os_sku = lookup(each.value, "os_sku", "Ubuntu") + os_type = lookup(each.value, "os_type", "Linux") + priority = lookup(each.value, "priority", "Regular") + proximity_placement_group_id = lookup(each.value, "proximity_placement_group_id", null) + spot_max_price = lookup(each.value, "spot_max_price", -1) + tags = merge(var.tags, lookup(each.value, "tags", {})) + scale_down_mode = lookup(each.value, "priority", "Regular") == "Regular" ? lookup(each.value, "scale_down_mode", "Delete") : "Delete" + ultra_ssd_enabled = lookup(each.value, "ultra_ssd_enabled", false) + vnet_subnet_id = var.vnet_subnet_id + workload_runtime = lookup(each.value, "workload_runtime", "OCIContainer") + zones = lookup(each.value, "zones", []) + max_count = lookup(each.value, "enable_auto_scaling", false) == true ? lookup(each.value, "max_count", null) : null + min_count = lookup(each.value, "enable_auto_scaling", false) == true ? lookup(each.value, "min_count", null) : null + node_count = lookup(each.value, "node_count", 0) +} diff --git a/modules/node-pools/outputs.tf b/modules/node-pools/outputs.tf new file mode 100644 index 00000000..e69de29b diff --git a/modules/node-pools/variables.tf b/modules/node-pools/variables.tf new file mode 100644 index 00000000..0ed7d033 --- /dev/null +++ b/modules/node-pools/variables.tf @@ -0,0 +1,15 @@ +variable "resource_group_name" { + type = string + description = "The resource group name to be imported" +} + +variable "cluster_name" { + type = string + description = "The name for the AKS cluster" +} + +variable "additional_node_pools" { + description = "Specify a map of node pools where key - the name if the pool, value - the object which represents the parameters for pool`s configuration. Dy default nothing will be createdy" + type = map(any) + default = {} +} \ No newline at end of file diff --git a/modules/node-pools/versions.tf b/modules/node-pools/versions.tf new file mode 100644 index 00000000..0a5b0a00 --- /dev/null +++ b/modules/node-pools/versions.tf @@ -0,0 +1,14 @@ +terraform { + required_version = ">= 1.2" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 3.21" + } + tls = { + source = "hashicorp/tls" + version = ">= 3.1" + } + } +}