Skip to content

Commit bc01cd9

Browse files
committed
AKS: Set defaults to prevent showing diff on every plan
* workload_autoscaler_profile set conditionally based on the block's attributes * upgrade_settings set default values to prevent plan diff and make configurable for default node pool
1 parent 18183ce commit bc01cd9

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

azurerm/_modules/aks/main.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ resource "azurerm_kubernetes_cluster" "current" {
3535
only_critical_addons_enabled = var.default_node_pool_only_critical_addons
3636

3737
zones = var.availability_zones
38+
39+
upgrade_settings {
40+
max_surge = var.upgade_settings_max_surge
41+
drain_timeout_in_minutes = var.upgade_settings_drain_timeout_in_minutes
42+
node_soak_duration_in_minutes = var.upgade_settings_node_soak_duration_in_minutes
43+
}
3844
}
3945

4046
network_profile {
@@ -75,9 +81,13 @@ resource "azurerm_kubernetes_cluster" "current" {
7581
}
7682
}
7783

78-
workload_autoscaler_profile {
79-
keda_enabled = var.keda_enabled
80-
vertical_pod_autoscaler_enabled = var.vertical_pod_autoscaler_enabled
84+
dynamic "workload_autoscaler_profile" {
85+
for_each = var.keda_enabled || var.vertical_pod_autoscaler_enabled ? toset([1]) : toset([])
86+
87+
content {
88+
keda_enabled = var.keda_enabled
89+
vertical_pod_autoscaler_enabled = var.vertical_pod_autoscaler_enabled
90+
}
8191
}
8292

8393
tags = var.metadata_labels

azurerm/_modules/aks/variables.tf

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,24 @@ variable "availability_zones" {
194194
variable "keda_enabled" {
195195
type = bool
196196
description = "Whether KEDA Autoscaler should be enabled for the cluster."
197-
default = false
198197
}
199198

200199
variable "vertical_pod_autoscaler_enabled" {
201200
type = bool
202201
description = "Whether Vertical Pod Autoscaler should be enabled for the cluster."
203-
default = false
204-
}
202+
}
203+
204+
variable "upgade_settings_drain_timeout_in_minutes" {
205+
type = number
206+
description = "The amount of time in minutes to wait on eviction of pods and graceful termination per node."
207+
}
208+
209+
variable "upgade_settings_max_surge" {
210+
type = string
211+
description = "The maximum number or percentage of nodes which will be added to the Node Pool size during an upgrade."
212+
}
213+
214+
variable "upgade_settings_node_soak_duration_in_minutes" {
215+
type = number
216+
description = "The amount of time in minutes to wait after draining a node and before reimaging and moving on to next node."
217+
}

azurerm/cluster/configuration.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ locals {
6767
additional_metadata_labels_tuples = [for t in split(",", local.additional_metadata_labels_lookup) : split("=", t)]
6868
additional_metadata_labels = { for t in local.additional_metadata_labels_tuples : t[0] => t[1] if length(t) == 2 }
6969

70-
keda_enabled = lookup(local.cfg, "keda_enabled", false)
70+
keda_enabled = lookup(local.cfg, "keda_enabled", false)
7171
vertical_pod_autoscaler_enabled = lookup(local.cfg, "vertical_pod_autoscaler_enabled", false)
72+
73+
upgade_settings_max_surge = lookup(local.cfg, "upgade_settings_max_surge", "10%")
74+
upgade_settings_drain_timeout_in_minutes = lookup(local.cfg, "upgade_settings_drain_timeout_in_minutes", 0)
75+
upgade_settings_node_soak_duration_in_minutes = lookup(local.cfg, "upgade_settings_node_soak_duration_in_minutes", 0)
7276
}

azurerm/cluster/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ module "cluster" {
6767

6868
availability_zones = local.availability_zones
6969

70-
keda_enabled = local.keda_enabled
70+
keda_enabled = local.keda_enabled
7171
vertical_pod_autoscaler_enabled = local.vertical_pod_autoscaler_enabled
72+
73+
upgade_settings_max_surge = local.upgade_settings_max_surge
74+
upgade_settings_drain_timeout_in_minutes = local.upgade_settings_drain_timeout_in_minutes
75+
upgade_settings_node_soak_duration_in_minutes = local.upgade_settings_node_soak_duration_in_minutes
7276
}

tests/aks_zero_cluster.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module "aks_zero" {
1313
default_node_pool_max_count = 1
1414

1515
network_plugin = "azure"
16+
17+
sku_tier = "Standard"
1618
}
1719

1820
# Settings for Ops-cluster

0 commit comments

Comments
 (0)