Skip to content

Commit 5721291

Browse files
authored
Merge pull request #15 from kpshjk/default_node_pool_upgrade_settings_max_surge
feat: pool upgrade settings, separate rbac_enabled for azure_active_directory_role_based_access_control, node_count as output parameter
2 parents 98095f4 + 0223bae commit 5721291

File tree

4 files changed

+96
-5
lines changed

4 files changed

+96
-5
lines changed

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ Type: `string`
124124

125125
The following input variables are optional (have default values):
126126

127+
### ad\_rbac\_enabled
128+
129+
Description: Defines RBAC for block azure\_active\_directory\_role\_based\_access\_control explicitly if set.
130+
Else RBAC for block azure\_active\_directory\_role\_based\_access\_control is set by "rbac\_enabled"
131+
132+
Type: `bool`
133+
134+
Default: `null`
135+
127136
### api\_server\_ip\_ranges
128137

129138
Description: The IP ranges to allow for incoming traffic to the server nodes. To disable the limitation, set an empty list as value (default).
@@ -132,7 +141,7 @@ Type: `list(string)`
132141

133142
Default: `[]`
134143

135-
### auto\_scaling\_enable
144+
### auto\_scaling\_enabled
136145

137146
Description: Enable auto-scaling of node pool
138147

@@ -156,7 +165,7 @@ Type: `string`
156165

157166
Default: `"1"`
158167

159-
### automatic\_channel\_upgrade
168+
### automatic\_upgrade\_channel
160169

161170
Description: Values:
162171
none, patch, stable, rapid, node-image
@@ -190,6 +199,24 @@ Type: `string`
190199

191200
Default: `"default"`
192201

202+
### default\_node\_pool\_upgrade\_settings\_enabled
203+
204+
Description: Values:
205+
false, true
206+
207+
Type: `bool`
208+
209+
Default: `false`
210+
211+
### default\_node\_pool\_upgrade\_settings\_max\_surge
212+
213+
Description: Example: "10%"
214+
see https://learn.microsoft.com/en-us/azure/aks/upgrade-aks-cluster?tabs=azure-cli#customize-node-surge-upgrade
215+
216+
Type: `string`
217+
218+
Default: `"10%"`
219+
193220
### dns\_prefix
194221

195222
Description: DNS-Prefix to use. Defaults to cluster name
@@ -206,6 +233,22 @@ Type: `number`
206233

207234
Default: `5`
208235

236+
### image\_cleaner\_enabled
237+
238+
Description: Azure default settings
239+
240+
Type: `bool`
241+
242+
Default: `false`
243+
244+
### image\_cleaner\_interval\_hours
245+
246+
Description: Azure default settings
247+
248+
Type: `number`
249+
250+
Default: `48`
251+
209252
### load\_balancer\_sku
210253

211254
Description: The SKU for the used Load Balancer
@@ -418,6 +461,10 @@ Description: The Kubernetes API host for a kubectl config
418461

419462
Description: The object ID of the service principal of the managed identity of the AKS
420463

464+
### node\_count
465+
466+
Description: n/a
467+
421468
### node\_resource\_group
422469

423470
Description: The resource group the Kubernetes nodes were created in

main.tf

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
*/
99

1010
locals {
11-
cluster_name = "${lower(var.project)}${lower(var.stage)}k8s"
11+
cluster_name = "${lower(var.project)}${lower(var.stage)}k8s"
1212
has_automatic_channel_upgrade_maintenance_window = var.automatic_upgrade_channel != "none" ? [
1313
var.automatic_upgrade_channel
1414
] : []
15+
has_default_node_pool_upgrade_settings = var.default_node_pool_upgrade_settings_enabled == true ? [
16+
var.default_node_pool_upgrade_settings_enabled
17+
] : []
1518
}
1619

1720
# Log analytics required for OMS Agent result processing - usually other logging solutions are used. Hence the affected tfsec rule is
@@ -61,6 +64,12 @@ resource "azurerm_kubernetes_cluster" "k8s" {
6164
auto_scaling_enabled = var.auto_scaling_enabled
6265
min_count = var.auto_scaling_min_node_count
6366
max_count = var.auto_scaling_max_node_count
67+
dynamic "upgrade_settings" {
68+
for_each = local.has_default_node_pool_upgrade_settings
69+
content {
70+
max_surge = var.default_node_pool_upgrade_settings_max_surge
71+
}
72+
}
6473
}
6574

6675
dynamic "api_server_access_profile" {
@@ -77,7 +86,7 @@ resource "azurerm_kubernetes_cluster" "k8s" {
7786
role_based_access_control_enabled = var.rbac_enabled
7887
azure_active_directory_role_based_access_control {
7988
admin_group_object_ids = var.rbac_managed_admin_groups
80-
azure_rbac_enabled = var.rbac_enabled
89+
azure_rbac_enabled = var.ad_rbac_enabled != null ? var.ad_rbac_enabled : var.rbac_enabled
8190
}
8291

8392
network_profile {

outputs.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,8 @@ output "public_outbound_ips" {
6666
output "managed_identity_object_id" {
6767
value = azurerm_kubernetes_cluster.k8s.identity[0].principal_id
6868
description = "The object ID of the service principal of the managed identity of the AKS"
69-
}
69+
}
70+
71+
output "node_count" {
72+
value = var.node_count
73+
}

vars.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ variable "rbac_enabled" {
6262
default = true
6363
}
6464

65+
variable "ad_rbac_enabled" {
66+
type = bool
67+
description = <<-EOF
68+
Defines RBAC for block azure_active_directory_role_based_access_control explicitly if set.
69+
Else RBAC for block azure_active_directory_role_based_access_control is set by "rbac_enabled"
70+
EOF
71+
default = null
72+
}
73+
6574
variable "rbac_managed_admin_groups" {
6675
type = list(string)
6776
description = "The group IDs that have admin access to the cluster. Have to be specified if rbac_enabled is true"
@@ -133,6 +142,10 @@ variable "availability_zones" {
133142
variable "temporary_name_for_rotation" {
134143
type = string
135144
description = "Specifies the name of the temporary node pool used to cycle the default node pool for VM resizing."
145+
validation {
146+
condition = var.temporary_name_for_rotation != null
147+
error_message = "The temporary_name_for_rotation value must not be null"
148+
}
136149
default = "rotationtmp"
137150
}
138151

@@ -270,3 +283,21 @@ variable "maintenance_window_auto_upgrade_utc_offset" {
270283
see https://learn.microsoft.com/en-us/azure/aks/planned-maintenance#creating-a-maintenance-window
271284
EOF
272285
}
286+
287+
variable "default_node_pool_upgrade_settings_enabled" {
288+
type = bool
289+
default = false
290+
description = <<-EOF
291+
If true, an upgrade_settings block will be added to default_node_pool.
292+
EOF
293+
}
294+
295+
variable "default_node_pool_upgrade_settings_max_surge" {
296+
type = string
297+
default = "10%"
298+
description = <<-EOF
299+
max_surge is a required parameter for an upgrade_settings block
300+
Example: "10%"
301+
see https://learn.microsoft.com/en-us/azure/aks/upgrade-aks-cluster?tabs=azure-cli#customize-node-surge-upgrade
302+
EOF
303+
}

0 commit comments

Comments
 (0)