diff --git a/README.md b/README.md
index 4dd4652c..e2f49cd7 100644
--- a/README.md
+++ b/README.md
@@ -176,7 +176,7 @@ Description: The node pools to create on the Kubernetes Cluster.
Type:
```hcl
-map(object({
+list(object({
vm_size = string
enable_auto_scaling = bool
max_count = number
@@ -193,8 +193,8 @@ map(object({
Default:
```json
-{
- "1": {
+[
+ {
"enable_auto_scaling": true,
"max_count": 110,
"min_count": 2,
@@ -203,7 +203,7 @@ Default:
"os_sku": "Ubuntu",
"vm_size": "Standard_D4d_v5"
},
- "2": {
+ {
"enable_auto_scaling": true,
"max_count": 110,
"min_count": 2,
@@ -212,7 +212,7 @@ Default:
"os_sku": "Ubuntu",
"vm_size": "Standard_D4d_v5"
},
- "3": {
+ {
"enable_auto_scaling": true,
"max_count": 110,
"min_count": 2,
@@ -221,7 +221,7 @@ Default:
"os_sku": "Ubuntu",
"vm_size": "Standard_D4d_v5"
}
-}
+]
```
### [private\_endpoints](#input\_private\_endpoints)
@@ -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_availability_zone/README.md b/examples/with_availability_zone/README.md
index 1cde1414..3d304773 100644
--- a/examples/with_availability_zone/README.md
+++ b/examples/with_availability_zone/README.md
@@ -1,5 +1,5 @@
-# AKS cluster with the region having availability zone
+# AKS cluster with region having availability zone
This deploys the module with a region that has availability zones.
@@ -18,14 +18,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"
@@ -122,12 +114,6 @@ Source: Azure/naming/azurerm
Version: >= 0.3.0
-### [regions](#module\_regions)
-
-Source: Azure/regions/azurerm
-
-Version: >= 0.3.0
-
### [test](#module\_test)
Source: ../../
diff --git a/examples/without_availability_zone/README.md b/examples/without_availability_zone/README.md
index 6a3a9cdf..51a80913 100644
--- a/examples/without_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 without availability zones
This deploys the module with a region that has no availability zones.
@@ -18,14 +18,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"
@@ -122,12 +114,6 @@ Source: Azure/naming/azurerm
Version: >= 0.3.0
-### [regions](#module\_regions)
-
-Source: Azure/regions/azurerm
-
-Version: >= 0.3.0
-
### [test](#module\_test)
Source: ../../
diff --git a/locals.tf b/locals.tf
index 0456daeb..725e1020 100644
--- a/locals.tf
+++ b/locals.tf
@@ -20,9 +20,9 @@ locals {
# 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)
-
+ # zones = try(formatlist("%s", module.regions.regions_by_name[var.location == null ? local.resource_group_location : var.location].zones), null)
+ zones = {
+ for zones in module.regions.regions_by_name_or_display_name[var.location == null ? local.resource_group_location : var.location].zones : zones => zones
+ }
}
diff --git a/main.tf b/main.tf
index 20b2ae87..3b39d823 100644
--- a/main.tf
+++ b/main.tf
@@ -39,7 +39,8 @@ resource "azurerm_kubernetes_cluster" "this" {
node_count = 5
os_sku = "Ubuntu"
tags = merge(var.tags, var.agents_tags)
- zones = try(module.regions.regions_by_name[coalesce(var.location, local.resource_group_location)].zones, null)
+ # convert to string the zones
+ zones = [for zone in local.zones : zone]
}
dynamic "identity" {
for_each = var.identity_ids != null ? [var.identity_ids] : []
@@ -66,18 +67,22 @@ resource "azurerm_management_lock" "this" {
resource "azurerm_kubernetes_cluster_node_pool" "this" {
# 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
+ # count = var.node_pools == null ? length(var.node_pools) : if zones is 3 multiple by 3
+ # if node pools are not emplty check if the node has a zone if yes then create a node pool per zone otherwise create a single node pool
+ count = var.node_pools != null ? length(var.node_pools) : local.zones != null ? 3 : 1
+
kubernetes_cluster_id = azurerm_kubernetes_cluster.this.id
- name = count.index
- vm_size = var.node_pools[count.index].vm_size
+ name = "agentpool${count.index + 1}"
+ vm_size = var.node_pools[count.index] == null ? var.node_pools[0].vm_size : var.node_pools[count.index].vm_size
enable_auto_scaling = true
- 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
+ max_count = var.node_pools[count.index] == null ? var.node_pools[0].vm_size : var.node_pools[count.index].max_count
+ min_count = var.node_pools[count.index] == null ? var.node_pools[0].vm_size : var.node_pools[count.index].min_count
+ node_count = var.node_pools[count.index] == null ? var.node_pools[0].vm_size : var.node_pools[count.index].node_count
+ os_sku = var.node_pools[count.index] == null ? var.node_pools[0].vm_size : var.node_pools[count.index].os_sku
tags = var.tags
- zones = local.zones[count.index]
+ zones = try(formatlist("%s", local.zones[(tonumber(count.index) + 1)]), null)
}
+
resource "azurerm_role_assignment" "this" {
for_each = var.role_assignments
diff --git a/variables.tf b/variables.tf
index aaf69b89..523fa7a8 100644
--- a/variables.tf
+++ b/variables.tf
@@ -96,7 +96,7 @@ variable "managed_identities" {
}
variable "node_pools" {
- type = map(object({
+ type = list(object({
vm_size = string
enable_auto_scaling = bool
max_count = number
@@ -108,8 +108,25 @@ variable "node_pools" {
tags = optional(map(string), {})
zones = optional(string)
}))
- default = {
- "1" = {
+ default = [{
+ vm_size = "Standard_D4d_v5"
+ enable_auto_scaling = true
+ max_count = 110
+ min_count = 2
+ node_count = 2
+ os_sku = "Ubuntu"
+ mode = "User"
+ },
+ {
+ vm_size = "Standard_D4d_v5"
+ enable_auto_scaling = true
+ max_count = 110
+ min_count = 2
+ node_count = 2
+ os_sku = "Ubuntu"
+ mode = "User"
+ },
+ {
vm_size = "Standard_D4d_v5"
enable_auto_scaling = true
max_count = 110
@@ -118,7 +135,7 @@ variable "node_pools" {
os_sku = "Ubuntu"
mode = "User"
}
- }
+ ]
description = "The node pools to create on the Kubernetes Cluster."
}