Skip to content

Commit 9b8796f

Browse files
committed
fix: migrate Azure FrontDoor/MySQL/PostgreSQL off retired single-server APIs
Three independent migrations bundled together because they share `modules/azure/client_factory.go` and `go.mod` updates: ## FrontDoor: classic -> CDN FrontDoor Azure deprecated classic FrontDoor on 2025-04-01; new creates fail. - examples/azure/terraform-azure-frontdoor-example: replace `azurerm_frontdoor` with `azurerm_cdn_frontdoor_profile` (Standard SKU) + endpoint + origin group + origin + route. `link_to_default_domain = true` on the route, no custom domain (minimal but real). - modules/azure/frontdoor.go: keep legacy armfrontdoor helpers (deprecated in godoc; classic FD remains modifiable through 2027-03-31). Add parallel `CDNFrontDoor*` helpers using armcdn (Get/Exists/Context/E/WithClient pattern). - modules/azure/client_factory.go: add armcdn imports and CDN client factories. - test/azure/terraform_azure_frontdoor_example_test.go: switch to new CDNFrontDoor* helpers. - go.mod: add armcdn v1.1.1. ## MySQL: Single Server -> Flexible Server Azure retired MySQL Single Server on 2024-09-16; new creates fail. - examples/azure/terraform-azure-mysqldb-example: replace `azurerm_mysql_server` / `_database` / `_firewall_rule` with `azurerm_mysql_flexible_server` / `_flexible_database` / `_flexible_server_firewall_rule`. SKU `B_Standard_B1ms`, version 8.0.21. - modules/azure/mysql.go + mysql_test.go: switch SDK from armmysql to armmysqlflexibleservers. Public Go function names preserved; struct fields adjust (storage MB -> GB, UserVisibleState -> State). - modules/azure/client_factory.go: switch MySQL factory to flexible-servers. - test/azure/terraform_azure_mysqldb_example_test.go: adjust struct field accesses for the new SDK types. - go.mod: replace armmysql v1.2.0 with armmysqlflexibleservers v1.2.0. ## PostgreSQL: Single Server -> Flexible Server Azure retired PostgreSQL Single Server on 2025-03-28; new creates fail. - examples/azure/terraform-azure-postgresql-example: replace `azurerm_postgresql_server` / `_database` with the flexible-server trio. SKU `B_Standard_B1ms`, version 14, locale `en_US.utf8`. - modules/azure/postgresql.go + postgresql_test.go: switch SDK from armpostgresql to armpostgresqlflexibleservers/v5 (v5 needed for the fake/ subpackage; renames DatabaseListResult -> DatabaseList). - modules/azure/client_factory.go: switch PostgreSQL factory. - go.mod: replace armpostgresql v1.2.0 with armpostgresqlflexibleservers/v5 v5.0.0. ## Verification - `go build -tags azure ./...` clean - `go vet -tags azure ./...` clean - `go test ./modules/azure/...` (unit tests with fakes) all pass - `terraform init -backend=false && terraform validate` succeeds in all three example directories
1 parent 56027bd commit 9b8796f

18 files changed

Lines changed: 514 additions & 231 deletions

File tree

Lines changed: 65 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# ---------------------------------------------------------------------------------------------------------------------
2-
# DEPLOY AN AZURE FRONT DOOR
3-
# This is an example of how to deploy an Azure Front Door with the minimum resources.
2+
# DEPLOY AN AZURE FRONT DOOR (CDN FRONT DOOR)
3+
# This is an example of how to deploy an Azure Front Door using the modern azurerm_cdn_frontdoor_* resource family.
4+
# The legacy `azurerm_frontdoor` resource was deprecated on April 1, 2025 and no longer permits creation of new
5+
# Front Door resources, so this example uses the CDN Front Door resources that supersede it.
46
# ---------------------------------------------------------------------------------------------------------------------
57
# See test/azure/terraform_azure_frontdoor_example_test.go for how to write automated tests for this code.
68
# ---------------------------------------------------------------------------------------------------------------------
@@ -30,51 +32,78 @@ resource "azurerm_resource_group" "rg" {
3032
}
3133

3234
# ---------------------------------------------------------------------------------------------------------------------
33-
# DEPLOY FRONT DOOR
35+
# DEPLOY THE CDN FRONT DOOR PROFILE
36+
# This is the top-level Front Door resource (replaces the classic `azurerm_frontdoor`).
3437
# ---------------------------------------------------------------------------------------------------------------------
3538

36-
resource "azurerm_frontdoor" "frontdoor" {
39+
resource "azurerm_cdn_frontdoor_profile" "frontdoor" {
3740
name = "terratest-afd-${var.postfix}"
3841
resource_group_name = azurerm_resource_group.rg.name
42+
sku_name = "Standard_AzureFrontDoor"
43+
}
3944

40-
backend_pool_settings {
41-
enforce_backend_pools_certificate_name_check = false
42-
}
45+
# ---------------------------------------------------------------------------------------------------------------------
46+
# DEPLOY THE FRONT DOOR ENDPOINT
47+
# A profile can host one or more endpoints (front-end host names).
48+
# ---------------------------------------------------------------------------------------------------------------------
4349

44-
routing_rule {
45-
name = "terratestRoutingRule1"
46-
accepted_protocols = ["Http", "Https"]
47-
patterns_to_match = ["/*"]
48-
frontend_endpoints = ["terratestEndpoint"]
49-
forwarding_configuration {
50-
forwarding_protocol = "MatchRequest"
51-
backend_pool_name = "terratestBackend"
52-
}
53-
}
50+
resource "azurerm_cdn_frontdoor_endpoint" "endpoint" {
51+
name = "terratest-ep-${var.postfix}"
52+
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.frontdoor.id
53+
}
54+
55+
# ---------------------------------------------------------------------------------------------------------------------
56+
# DEPLOY THE ORIGIN GROUP AND ORIGIN
57+
# An origin group describes how the Front Door load-balances and health-checks a set of origins.
58+
# ---------------------------------------------------------------------------------------------------------------------
59+
60+
resource "azurerm_cdn_frontdoor_origin_group" "origin_group" {
61+
name = "terratestOriginGroup"
62+
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.frontdoor.id
5463

55-
backend_pool_load_balancing {
56-
name = "terratestLoadBalanceSetting"
64+
load_balancing {
65+
sample_size = 4
66+
successful_samples_required = 3
5767
}
5868

59-
backend_pool_health_probe {
60-
name = "terratestHealthProbeSetting"
69+
health_probe {
70+
interval_in_seconds = 100
71+
path = "/"
72+
protocol = "Https"
73+
request_type = "HEAD"
6174
}
75+
}
6276

63-
backend_pool {
64-
name = "terratestBackend"
65-
backend {
66-
host_header = var.backend_host
67-
address = var.backend_host
68-
http_port = 80
69-
https_port = 443
70-
}
77+
resource "azurerm_cdn_frontdoor_origin" "origin" {
78+
name = "terratestOrigin"
79+
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.origin_group.id
7180

72-
load_balancing_name = "terratestLoadBalanceSetting"
73-
health_probe_name = "terratestHealthProbeSetting"
74-
}
81+
enabled = true
82+
host_name = var.backend_host
83+
http_port = 80
84+
https_port = 443
85+
origin_host_header = var.backend_host
86+
priority = 1
87+
weight = 1000
88+
certificate_name_check_enabled = true
89+
}
7590

76-
frontend_endpoint {
77-
name = "terratestEndpoint"
78-
host_name = "terratest-afd-${var.postfix}.azurefd.net"
79-
}
91+
# ---------------------------------------------------------------------------------------------------------------------
92+
# DEPLOY THE ROUTE
93+
# Routes wire an endpoint to an origin group with a forwarding/caching configuration.
94+
# ---------------------------------------------------------------------------------------------------------------------
95+
96+
resource "azurerm_cdn_frontdoor_route" "route" {
97+
name = "terratestRoute"
98+
cdn_frontdoor_endpoint_id = azurerm_cdn_frontdoor_endpoint.endpoint.id
99+
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.origin_group.id
100+
cdn_frontdoor_origin_ids = [azurerm_cdn_frontdoor_origin.origin.id]
101+
102+
enabled = true
103+
forwarding_protocol = "MatchRequest"
104+
https_redirect_enabled = false
105+
patterns_to_match = ["/*"]
106+
supported_protocols = ["Http", "Https"]
107+
108+
link_to_default_domain = true
80109
}

examples/azure/terraform-azure-frontdoor-example/output.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ output "resource_group_name" {
33
}
44

55
output "front_door_name" {
6-
description = "Specifies the name of the Front Door service."
7-
value = azurerm_frontdoor.frontdoor.name
6+
description = "Specifies the name of the CDN Front Door profile (replaces the legacy Front Door service name)."
7+
value = azurerm_cdn_frontdoor_profile.frontdoor.name
88
}
99

1010
output "front_door_url" {
11-
description = "Specifies the host name of the frontend_endpoint. Must be a domain name."
12-
value = azurerm_frontdoor.frontdoor.frontend_endpoint[0].host_name
11+
description = "Specifies the host name (FQDN) of the Front Door endpoint."
12+
value = azurerm_cdn_frontdoor_endpoint.endpoint.host_name
1313
}
1414

1515
output "front_door_endpoint_name" {
16-
description = "Specifies the friendly name of the frontend_endpoint"
17-
value = azurerm_frontdoor.frontdoor.frontend_endpoint[0].name
18-
}
16+
description = "Specifies the name of the Front Door endpoint."
17+
value = azurerm_cdn_frontdoor_endpoint.endpoint.name
18+
}

examples/azure/terraform-azure-mysqldb-example/main.tf

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# ---------------------------------------------------------------------------------------------------------------------
2-
# DEPLOY AN AZURE MySQL Database
3-
# This is an example of how to deploy an Azure Mysql database.
2+
# DEPLOY AN AZURE MySQL FLEXIBLE SERVER + DATABASE
3+
# This is an example of how to deploy an Azure MySQL Flexible Server and database.
44
# See test/terraform_azure_example_test.go for how to write automated tests for this code.
5+
#
6+
# NOTE: The legacy `azurerm_mysql_server` (MySQL Single Server) was retired by Azure on 2024-09-16.
7+
# This example uses the modern flexible server resources, which are the supported replacement.
58
# ---------------------------------------------------------------------------------------------------------------------
69

710

@@ -33,7 +36,7 @@ resource "azurerm_resource_group" "mysql_rg" {
3336
}
3437

3538
# ---------------------------------------------------------------------------------------------------------------------
36-
# DEPLOY AZURE MySQL SERVER
39+
# DEPLOY AZURE MySQL FLEXIBLE SERVER
3740
# ---------------------------------------------------------------------------------------------------------------------
3841

3942
# Random password is used as an example to simplify the deployment and improve the security of the database.
@@ -47,35 +50,46 @@ resource "random_password" "password" {
4750
min_special = "1"
4851
}
4952

50-
resource "azurerm_mysql_server" "mysqlserver" {
53+
resource "azurerm_mysql_flexible_server" "mysqlserver" {
5154
name = "mysqlserver-${var.postfix}"
5255
location = azurerm_resource_group.mysql_rg.location
5356
resource_group_name = azurerm_resource_group.mysql_rg.name
5457

55-
administrator_login = var.mysqlserver_admin_login
56-
administrator_login_password = random_password.password.result
58+
administrator_login = var.mysqlserver_admin_login
59+
administrator_password = random_password.password.result
5760

58-
sku_name = var.mysqlserver_sku_name
59-
storage_mb = var.mysqlserver_storage_mb
60-
version = "5.7"
61+
sku_name = var.mysqlserver_sku_name
62+
version = var.mysqlserver_version
6163

62-
auto_grow_enabled = true
63-
geo_redundant_backup_enabled = false
64-
infrastructure_encryption_enabled = true
65-
backup_retention_days = 7
66-
public_network_access_enabled = false
67-
ssl_enforcement_enabled = true
68-
ssl_minimal_tls_version_enforced = "TLS1_2"
64+
backup_retention_days = 7
65+
66+
storage {
67+
size_gb = var.mysqlserver_storage_size_gb
68+
auto_grow_enabled = true
69+
}
6970
}
7071

7172
# ---------------------------------------------------------------------------------------------------------------------
72-
# DEPLOY AZURE MySQL DATABASE
73+
# DEPLOY AZURE MySQL FLEXIBLE DATABASE
7374
# ---------------------------------------------------------------------------------------------------------------------
7475

75-
resource "azurerm_mysql_database" "mysqldb" {
76+
resource "azurerm_mysql_flexible_database" "mysqldb" {
7677
name = "mysqldb-${var.postfix}"
7778
resource_group_name = azurerm_resource_group.mysql_rg.name
78-
server_name = azurerm_mysql_server.mysqlserver.name
79+
server_name = azurerm_mysql_flexible_server.mysqlserver.name
7980
charset = var.mysqldb_charset
8081
collation = var.mysqldb_collation
8182
}
83+
84+
# ---------------------------------------------------------------------------------------------------------------------
85+
# DEPLOY AZURE MySQL FLEXIBLE SERVER FIREWALL RULE
86+
# Allow access from the Azure backbone (0.0.0.0) so the test runner can reach the server.
87+
# ---------------------------------------------------------------------------------------------------------------------
88+
89+
resource "azurerm_mysql_flexible_server_firewall_rule" "allow_azure" {
90+
name = "AllowAzureServices"
91+
resource_group_name = azurerm_resource_group.mysql_rg.name
92+
server_name = azurerm_mysql_flexible_server.mysqlserver.name
93+
start_ip_address = "0.0.0.0"
94+
end_ip_address = "0.0.0.0"
95+
}

examples/azure/terraform-azure-mysqldb-example/outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ output "resource_group_name" {
33
}
44

55
output "mysql_server_name" {
6-
value = azurerm_mysql_server.mysqlserver.name
6+
value = azurerm_mysql_flexible_server.mysqlserver.name
77
}
88

99
output "sql_server_full_domain_name" {
10-
value = azurerm_mysql_server.mysqlserver.fqdn
10+
value = azurerm_mysql_flexible_server.mysqlserver.fqdn
1111
}
1212

1313
output "sql_server_admin_login" {
14-
value = azurerm_mysql_server.mysqlserver.administrator_login
14+
value = azurerm_mysql_flexible_server.mysqlserver.administrator_login
1515
}
1616

1717
output "sql_server_admin_login_pass" {
18-
value = azurerm_mysql_server.mysqlserver.administrator_login_password
18+
value = azurerm_mysql_flexible_server.mysqlserver.administrator_password
1919
sensitive = true
2020
}
2121

2222
output "mysql_database_name" {
23-
value = azurerm_mysql_database.mysqldb.name
23+
value = azurerm_mysql_flexible_database.mysqldb.name
2424
}

examples/azure/terraform-azure-mysqldb-example/variables.tf

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,37 @@ variable "location" {
2525
}
2626

2727
variable "mysqlserver_admin_login" {
28-
description = "The administrator login name for the mysql server."
28+
description = "The administrator login name for the mysql flexible server."
2929
type = string
3030
default = "mysqladmin"
3131
}
3232

3333
variable "mysqlserver_sku_name" {
34-
description = "The SKU name for the mysql server."
34+
description = "The SKU name for the mysql flexible server (Burstable / GeneralPurpose / MemoryOptimized)."
3535
type = string
36-
default = "GP_Gen5_2"
36+
default = "B_Standard_B1ms"
3737
}
3838

39-
variable "mysqlserver_storage_mb" {
40-
description = "The Max storage allowed for mysql server."
39+
variable "mysqlserver_storage_size_gb" {
40+
description = "The max storage allowed (in GB) for the mysql flexible server."
41+
type = number
42+
default = 20
43+
}
44+
45+
variable "mysqlserver_version" {
46+
description = "The MySQL engine version for the flexible server."
4147
type = string
42-
default = "5120"
48+
default = "8.0.21"
4349
}
4450

4551
variable "mysqldb_charset" {
46-
description = "The charset for mysql data base."
52+
description = "The charset for the mysql database."
4753
type = string
4854
default = "utf8"
4955
}
5056

5157
variable "mysqldb_collation" {
52-
description = "The collation for mysql data base."
58+
description = "The collation for the mysql database."
5359
type = string
5460
default = "utf8_unicode_ci"
5561
}

0 commit comments

Comments
 (0)