Skip to content

Commit b082101

Browse files
committed
auto-upgrade: variable orchestrator_version to null
1 parent e3f7a5c commit b082101

3 files changed

Lines changed: 57 additions & 6 deletions

File tree

locals.tf

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
locals {
22
# automatic upgrades are either:
3-
# - null
4-
# - patch, but then the kubernetes_version musnt't specify a patch number
5-
# - rapid/stable/node-image, but then the kubernetes_version must be null
3+
# - null
4+
# - patch, but then the kubernetes_version must not specify a patch number and orchestrator_version must be null
5+
# - rapid/stable/node-image, but then the kubernetes_version and the orchestrator_version must be null
66
automatic_channel_upgrade_check = var.automatic_channel_upgrade == null ? true : (
77
contains(["patch"], var.automatic_channel_upgrade) &&
8-
can(regex("^[0-9]{1,}\\.[0-9]{1,}$", var.kubernetes_version))
8+
can(regex("^[0-9]{1,}\\.[0-9]{1,}$", var.kubernetes_version)) &&
9+
var.orchestrator_version == null
910
) ? true : (
1011
contains(["rapid", "stable", "node-image"], var.automatic_channel_upgrade) &&
11-
var.kubernetes_version == null
12+
var.kubernetes_version == null &&
13+
var.orchestrator_version == null
1214
)
1315
# Abstract the decision whether to create an Analytics Workspace or not.
1416
create_analytics_solution = var.log_analytics_workspace_enabled && var.log_analytics_solution_id == null

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ resource "azurerm_kubernetes_cluster" "main" {
241241
}
242242
precondition {
243243
condition = local.automatic_channel_upgrade_check
244-
error_message = "Either disable automatic upgrades, only specify up to the minor version when using `automatic_channel_upgrade=patch` or don't specify `kubernetes_version` at all when using `automatic_channel_upgrade=stable|rapid|node-image`."
244+
error_message = "Either disable automatic upgrades, or only specify up to the minor version when using `automatic_channel_upgrade=patch` or don't specify `kubernetes_version` at all when using `automatic_channel_upgrade=stable|rapid|node-image`. With automatic upgrades `orchestrator_version` must be set to `null`."
245245
}
246246
}
247247
}

test/unit/unit_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,55 @@ func TestAutomaticUpgrades(t *testing.T) {
150150
}
151151
}
152152

153+
func TestInvalidVarsForAutomaticUpgrades(t *testing.T) {
154+
testCases := map[string]struct {
155+
name string
156+
vars map[string]interface{}
157+
}{
158+
"automatic_patches_with_patch_number_specified": {
159+
vars: map[string]interface{}{
160+
"prefix": "foo",
161+
"resource_group_name": "bar",
162+
"automatic_channel_upgrade": "patch",
163+
"kubernetes_version": "1.25.3",
164+
"orchestrator_version": "1.25.3",
165+
},
166+
},
167+
"automatic_upgrades_to_newest_version_with_fixed_versions": {
168+
vars: map[string]interface{}{
169+
"prefix": "foo",
170+
"resource_group_name": "bar",
171+
"automatic_channel_upgrade": "rapid",
172+
"kubernetes_version": "1.25.3",
173+
"orchestrator_version": "1.24",
174+
},
175+
},
176+
"automatic_upgrades_to_stable_version_with_orchestrator": {
177+
vars: map[string]interface{}{
178+
"prefix": "foo",
179+
"resource_group_name": "bar",
180+
"automatic_channel_upgrade": "stable",
181+
"orchestrator_version": "1.24",
182+
},
183+
},
184+
}
185+
186+
for name, tt := range testCases {
187+
t.Run(name, func(t *testing.T) {
188+
test_helper.RunE2ETest(t, "../../", "unit-test-fixture",
189+
terraform.Options{
190+
Upgrade: false,
191+
Vars: tt.vars,
192+
},
193+
func(t *testing.T, output test_helper.TerraformOutput) {
194+
upgrades, ok := output["automatic_channel_upgrade_check"].(bool)
195+
assert.True(t, ok)
196+
assert.False(t, upgrades)
197+
})
198+
})
199+
}
200+
}
201+
153202
func dummyRequiredVariables() map[string]interface{} {
154203
return map[string]interface{}{
155204
"prefix": "foo",

0 commit comments

Comments
 (0)