Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nellyk committed Mar 4, 2024
1 parent deeee1c commit 1dc4d1b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 54 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -193,8 +193,8 @@ map(object({
Default:

```json
{
"1": {
[
{
"enable_auto_scaling": true,
"max_count": 110,
"min_count": 2,
Expand All @@ -203,7 +203,7 @@ Default:
"os_sku": "Ubuntu",
"vm_size": "Standard_D4d_v5"
},
"2": {
{
"enable_auto_scaling": true,
"max_count": 110,
"min_count": 2,
Expand All @@ -212,7 +212,7 @@ Default:
"os_sku": "Ubuntu",
"vm_size": "Standard_D4d_v5"
},
"3": {
{
"enable_auto_scaling": true,
"max_count": 110,
"min_count": 2,
Expand All @@ -221,7 +221,7 @@ Default:
"os_sku": "Ubuntu",
"vm_size": "Standard_D4d_v5"
}
}
]
```

### <a name="input_private_endpoints"></a> [private\_endpoints](#input\_private\_endpoints)
Expand Down Expand Up @@ -331,7 +331,7 @@ Description: This is the full output for the resource.

## Modules

The following modules are called:
The following Modules are called:

### <a name="module_regions"></a> [regions](#module\_regions)

Expand Down
16 changes: 1 addition & 15 deletions examples/with_availability_zone/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- BEGIN_TF_DOCS -->
# 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.

Expand All @@ -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"
Expand Down Expand Up @@ -122,12 +114,6 @@ Source: Azure/naming/azurerm

Version: >= 0.3.0

### <a name="module_regions"></a> [regions](#module\_regions)

Source: Azure/regions/azurerm

Version: >= 0.3.0

### <a name="module_test"></a> [test](#module\_test)

Source: ../../
Expand Down
16 changes: 1 addition & 15 deletions examples/without_availability_zone/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- BEGIN_TF_DOCS -->
# 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.

Expand All @@ -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"
Expand Down Expand Up @@ -122,12 +114,6 @@ Source: Azure/naming/azurerm

Version: >= 0.3.0

### <a name="module_regions"></a> [regions](#module\_regions)

Source: Azure/regions/azurerm

Version: >= 0.3.0

### <a name="module_test"></a> [test](#module\_test)

Source: ../../
Expand Down
8 changes: 4 additions & 4 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

23 changes: 14 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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] : []
Expand All @@ -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

Expand Down
25 changes: 21 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -118,7 +135,7 @@ variable "node_pools" {
os_sku = "Ubuntu"
mode = "User"
}
}
]
description = "The node pools to create on the Kubernetes Cluster."
}

Expand Down

0 comments on commit 1dc4d1b

Please sign in to comment.