Skip to content

Commit f6db2ec

Browse files
committed
fix(terraform): default to a Kubernetes version AKS still builds, and stop recreating built-in databases
Two failures from a real apply that were previously only worked around in the consuming root. AKS refused the cluster with K8sVersionNotSupported: 1.33 has aged out of standard support into Long-Term-Support only, and AKS will not build on an LTS-only version without the cluster opting into LTS first. The default moves to 1.34, and the description now says where the line is and how to check it, since this recurs every time a version ages out. PostgreSQL Flexible Server ships a database called postgres, so asking Terraform to create one by that name failed with 'already exists' -- and postgres was the module default, meaning the default configuration could not apply at all. Naming a database the server ships is now read as 'use the one that is there' rather than as an error, and the output reports what Onyx connects to either way. Neither is visible to the mocked tests: one is a service-side support policy and the other is a resource the server creates on its own.
1 parent 1951111 commit f6db2ec

6 files changed

Lines changed: 60 additions & 6 deletions

File tree

deployment/terraform/modules/azure/aks/tests/aks.tftest.hcl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ run "defaults" {
4747
}
4848
}
4949

50+
run "the_default_version_is_one_azure_still_builds" {
51+
command = plan
52+
53+
# Versions age out of standard support into Long-Term-Support only, and AKS
54+
# then refuses to build a cluster on them. 1.33 crossed that line.
55+
assert {
56+
condition = azurerm_kubernetes_cluster.this.kubernetes_version == "1.34"
57+
error_message = "The default version must be one AKS will still build without an LTS opt-in."
58+
}
59+
}
60+
5061
run "dns_service_ip_is_derived_from_the_service_range" {
5162
command = plan
5263

deployment/terraform/modules/azure/aks/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ variable "location" {
1515

1616
variable "kubernetes_version" {
1717
type = string
18-
description = "Kubernetes version for the control plane. Move one minor at a time."
19-
default = "1.33"
18+
description = "Kubernetes version for the control plane. Move one minor at a time. Versions age out of standard support and become Long-Term-Support only, at which point AKS refuses to build a cluster on them: check with az aks get-versions."
19+
default = "1.34"
2020
}
2121

2222
variable "subnet_id" {

deployment/terraform/modules/azure/onyx/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ variable "redis_high_availability_enabled" {
283283

284284
variable "kubernetes_version" {
285285
type = string
286-
description = "Kubernetes version for the control plane"
287-
default = "1.33"
286+
description = "Kubernetes version for the control plane Versions age out of standard support and become Long-Term-Support only, at which point AKS refuses to build a cluster on them: check with az aks get-versions."
287+
default = "1.34"
288288
}
289289

290290
variable "main_node_vm_size" {

deployment/terraform/modules/azure/postgres/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
locals {
2+
# Flexible Server ships these already. Asking Terraform to create one by any
3+
# of these names fails with "already exists", so naming one is read as "use
4+
# the database that is already there" rather than as an error.
5+
builtin_databases = ["postgres", "azure_maintenance", "azure_sys"]
6+
create_database = !contains(local.builtin_databases, var.db_name)
7+
28
create_private_dns_zone = var.private_dns_zone_id == null
39
private_dns_zone_id = local.create_private_dns_zone ? azurerm_private_dns_zone.this[0].id : var.private_dns_zone_id
410

@@ -115,6 +121,8 @@ resource "azurerm_postgresql_flexible_server_active_directory_administrator" "th
115121
}
116122

117123
resource "azurerm_postgresql_flexible_server_database" "this" {
124+
count = local.create_database ? 1 : 0
125+
118126
name = var.db_name
119127
server_id = azurerm_postgresql_flexible_server.this.id
120128
charset = "UTF8"

deployment/terraform/modules/azure/postgres/outputs.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ output "port" {
1818
value = 5432
1919
}
2020

21+
# Reported from the variable rather than the resource, because a database the
22+
# server ships is not one this module creates.
2123
output "db_name" {
22-
description = "Name of the database created on the server"
23-
value = azurerm_postgresql_flexible_server_database.this.name
24+
description = "Name of the database Onyx connects to, whether this module created it or the server shipped it"
25+
value = var.db_name
2426
}
2527

2628
output "username" {

deployment/terraform/modules/azure/postgres/tests/postgres.tftest.hcl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,39 @@ run "an_existing_dns_zone_is_reused" {
152152
}
153153
}
154154

155+
run "a_database_the_server_ships_is_not_recreated" {
156+
command = plan
157+
158+
# Flexible Server already has one called "postgres"; creating it fails with
159+
# "already exists".
160+
variables {
161+
db_name = "postgres"
162+
}
163+
164+
assert {
165+
condition = length(azurerm_postgresql_flexible_server_database.this) == 0
166+
error_message = "Naming a built-in database should mean use it, not create it."
167+
}
168+
169+
assert {
170+
condition = output.db_name == "postgres"
171+
error_message = "The output still reports what Onyx connects to."
172+
}
173+
}
174+
175+
run "a_database_of_our_own_is_created" {
176+
command = plan
177+
178+
variables {
179+
db_name = "onyx"
180+
}
181+
182+
assert {
183+
condition = length(azurerm_postgresql_flexible_server_database.this) == 1
184+
error_message = "A name the server does not ship should be created."
185+
}
186+
}
187+
155188
run "no_entra_administrator_by_default" {
156189
command = plan
157190

0 commit comments

Comments
 (0)