diff --git a/README.md b/README.md index a06bf4f4..4dd4652c 100644 --- a/README.md +++ b/README.md @@ -331,7 +331,7 @@ Description: This is the full output for the resource. ## Modules -The following Modules are called: +The following modules are called: ### [regions](#module\_regions) diff --git a/examples/with_region_having_availability_zone/README.md b/examples/with_availability_zone/README.md similarity index 98% rename from examples/with_region_having_availability_zone/README.md rename to examples/with_availability_zone/README.md index d7658270..1cde1414 100644 --- a/examples/with_region_having_availability_zone/README.md +++ b/examples/with_availability_zone/README.md @@ -1,5 +1,5 @@ -# AKS cluster with region having availability zone +# AKS cluster with the region having availability zone This deploys the module with a region that has availability zones. diff --git a/examples/with_region_having_availability_zone/_footer.md b/examples/with_availability_zone/_footer.md similarity index 100% rename from examples/with_region_having_availability_zone/_footer.md rename to examples/with_availability_zone/_footer.md diff --git a/examples/with_region_having_availability_zone/_header.md b/examples/with_availability_zone/_header.md similarity index 100% rename from examples/with_region_having_availability_zone/_header.md rename to examples/with_availability_zone/_header.md diff --git a/examples/with_region_having_availability_zone/main.tf b/examples/with_availability_zone/main.tf similarity index 85% rename from examples/with_region_having_availability_zone/main.tf rename to examples/with_availability_zone/main.tf index 5c5b64d1..d44f9c6c 100644 --- a/examples/with_region_having_availability_zone/main.tf +++ b/examples/with_availability_zone/main.tf @@ -12,14 +12,6 @@ provider "azurerm" { features {} } - -## Section to provide a random Azure region for the resource group -# This allows us to randomize the region for the resource group. -module "regions" { - source = "Azure/regions/azurerm" - version = ">= 0.3.0" -} - # This ensures we have unique CAF compliant names for our resources. module "naming" { source = "Azure/naming/azurerm" diff --git a/examples/with_region_having_availability_zone/variables.tf b/examples/with_availability_zone/variables.tf similarity index 100% rename from examples/with_region_having_availability_zone/variables.tf rename to examples/with_availability_zone/variables.tf diff --git a/examples/with_region_having_no_availability_zone/README.md b/examples/without_availability_zone/README.md similarity index 98% rename from examples/with_region_having_no_availability_zone/README.md rename to examples/without_availability_zone/README.md index f85b23f1..6a3a9cdf 100644 --- a/examples/with_region_having_no_availability_zone/README.md +++ b/examples/without_availability_zone/README.md @@ -1,5 +1,5 @@ -# AKS cluster with region having no availability zone +# AKS cluster with region having no availability zone This deploys the module with a region that has no availability zones. diff --git a/examples/with_region_having_no_availability_zone/_footer.md b/examples/without_availability_zone/_footer.md similarity index 100% rename from examples/with_region_having_no_availability_zone/_footer.md rename to examples/without_availability_zone/_footer.md diff --git a/examples/with_region_having_no_availability_zone/_header.md b/examples/without_availability_zone/_header.md similarity index 56% rename from examples/with_region_having_no_availability_zone/_header.md rename to examples/without_availability_zone/_header.md index 5f04ee95..6ab8e1e9 100644 --- a/examples/with_region_having_no_availability_zone/_header.md +++ b/examples/without_availability_zone/_header.md @@ -1,3 +1,3 @@ -# AKS cluster with region having no availability zone +# AKS cluster without availability zones This deploys the module with a region that has no availability zones. diff --git a/examples/with_region_having_no_availability_zone/main.tf b/examples/without_availability_zone/main.tf similarity index 86% rename from examples/with_region_having_no_availability_zone/main.tf rename to examples/without_availability_zone/main.tf index 8136bff5..980df2ac 100644 --- a/examples/with_region_having_no_availability_zone/main.tf +++ b/examples/without_availability_zone/main.tf @@ -12,14 +12,6 @@ provider "azurerm" { features {} } - -## Section to provide a random Azure region for the resource group -# This allows us to randomize the region for the resource group. -module "regions" { - source = "Azure/regions/azurerm" - version = ">= 0.3.0" -} - # This ensures we have unique CAF compliant names for our resources. module "naming" { source = "Azure/naming/azurerm" diff --git a/examples/with_region_having_no_availability_zone/variables.tf b/examples/without_availability_zone/variables.tf similarity index 100% rename from examples/with_region_having_no_availability_zone/variables.tf rename to examples/without_availability_zone/variables.tf diff --git a/locals.tf b/locals.tf index c4b6abad..0456daeb 100644 --- a/locals.tf +++ b/locals.tf @@ -15,4 +15,14 @@ locals { } ] ]) : "${assoc.pe_key}-${assoc.asg_key}" => assoc } -} \ No newline at end of file +} + + +# check if zone is available and return the zone if it is available +locals { +# zones = try(formatlist("%s", module.regions.regions_by_name[var.location == null ? local.resource_group_location : var.location].zones[(tonumber(count.index) - 1)]), null) + # remove the count and use something else for index + zones = try(formatlist("%s", module.regions.regions_by_name[var.location == null ? local.resource_group_location : var.location].zones), null) + +} + diff --git a/main.tf b/main.tf index a27c9d75..20b2ae87 100644 --- a/main.tf +++ b/main.tf @@ -64,19 +64,19 @@ resource "azurerm_management_lock" "this" { } resource "azurerm_kubernetes_cluster_node_pool" "this" { - # set max nodepools created to 3 - for_each = var.node_pools - + # if the region has zone create a node pool per zone + # if the region does not have zone create a single node pool with the zone as null + count = var.node_pools != null ? length(var.node_pools) == 1 ? 3 : length(var.node_pools) : 0 kubernetes_cluster_id = azurerm_kubernetes_cluster.this.id - name = "userpool${each.key}" - vm_size = each.value.vm_size + name = count.index + vm_size = var.node_pools[count.index].vm_size enable_auto_scaling = true - max_count = each.value.max_count - min_count = each.value.min_count - node_count = each.value.node_count - os_sku = each.value.os_sku + max_count = var.node_pools[count.index].max_count + min_count = var.node_pools[count.index].min_count + node_count = var.node_pools[count.index].node_count + os_sku = var.node_pools[count.index].os_sku tags = var.tags - zones = try(formatlist("%s", module.regions.regions_by_name[var.location == null ? local.resource_group_location : var.location].zones[(tonumber(each.key) - 1)]), null) + zones = local.zones[count.index] } resource "azurerm_role_assignment" "this" { for_each = var.role_assignments diff --git a/variables.tf b/variables.tf index dd3054aa..aaf69b89 100644 --- a/variables.tf +++ b/variables.tf @@ -117,32 +117,9 @@ variable "node_pools" { node_count = 2 os_sku = "Ubuntu" mode = "User" - }, - "2" = { - vm_size = "Standard_D4d_v5" - enable_auto_scaling = true - max_count = 110 - min_count = 2 - node_count = 2 - os_sku = "Ubuntu" - mode = "User" - }, - "3" = { - vm_size = "Standard_D4d_v5" - enable_auto_scaling = true - max_count = 110 - min_count = 2 - node_count = 2 - os_sku = "Ubuntu" - mode = "User" } } description = "The node pools to create on the Kubernetes Cluster." - - validation { - condition = var.node_pools != null && length((var.node_pools)) >= 3 - error_message = "The minimum number of user node pools recommended to users to create is 3" - } } variable "private_endpoints" {