Skip to content

Commit b9d42cf

Browse files
Updated FD templates according to migrated FD example
1 parent 118d8b5 commit b9d42cf

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

modules/azure/frontdoor_standard/main.tf

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,26 @@ resource "azurerm_cdn_frontdoor_profile" "fd_profile" {
2222
sku_name = "Standard_AzureFrontDoor"
2323
}
2424

25-
# Endpoints
26-
resource "azurerm_cdn_frontdoor_endpoint" "fd_endpoints" {
27-
for_each = { for endpoint in var.endpoints : endpoint => endpoint }
25+
# Endpoint
26+
resource "azurerm_cdn_frontdoor_endpoint" "fd_endpoint" {
27+
name = var.name
28+
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.fd_profile.id
29+
}
2830

29-
name = each.value
31+
# Default FD domain
32+
resource "azurerm_cdn_frontdoor_custom_domain" "fd_default_domain" {
33+
name = "default"
3034
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.fd_profile.id
35+
host_name = "{var.name}.azurefd.net"
36+
37+
tls {
38+
certificate_type = "ManagedCertificate"
39+
}
3140
}
3241

3342
# Custom domains
3443
resource "azurerm_cdn_frontdoor_custom_domain" "fd_custom_domains" {
35-
for_each = { for fd_endpoint in azurerm_cdn_frontdoor_endpoint.fd_endpoints : fd_endpoint.name => fd_endpoint }
44+
for_each = { for custom_domain in var.custom_domains: custom_domain.name => custom_domain }
3645

3746
name = each.key
3847
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.fd_profile.id
@@ -113,16 +122,17 @@ resource "azurerm_cdn_frontdoor_route" "fd_redirect_routes" {
113122
for route in var.redirect_routes : route.name => route
114123
}
115124

116-
name = each.key
117-
cdn_frontdoor_endpoint_id = azurerm_cdn_frontdoor_endpoint.fd_endpoints[each.value.frontend_endpoint].id
118-
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.fd_origin_groups[each.value.origin_group_name].id
119-
cdn_frontdoor_origin_ids = [azurerm_cdn_frontdoor_origin.fd_origins[each.value.origin_group_name].id]
120-
cdn_frontdoor_rule_set_ids = [azurerm_cdn_frontdoor_rule_set.fd_rs_redirect.id]
121-
enabled = lookup(each.value, "enabled", true)
122-
123-
patterns_to_match = each.value.patterns_to_match
124-
supported_protocols = each.value.supported_protocols
125-
https_redirect_enabled = false
125+
name = each.key
126+
cdn_frontdoor_endpoint_id = azurerm_cdn_frontdoor_endpoint.fd_endpoint.id
127+
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.fd_origin_groups[each.value.origin_group_name].id
128+
cdn_frontdoor_origin_ids = [azurerm_cdn_frontdoor_origin.fd_origins[each.value.origin_group_name].id]
129+
cdn_frontdoor_rule_set_ids = [azurerm_cdn_frontdoor_rule_set.fd_rs_redirect.id]
130+
cdn_frontdoor_custom_domain_ids = [azurerm_cdn_frontdoor_custom_domain.fd_custom_domains[each.value.custom_domain_name].id]
131+
132+
enabled = each.value.enabled
133+
patterns_to_match = each.value.patterns_to_match
134+
supported_protocols = each.value.supported_protocols
135+
https_redirect_enabled = false
126136
}
127137

128138
# Routes (forwarding)
@@ -132,16 +142,15 @@ resource "azurerm_cdn_frontdoor_route" "fd_forwarding_routes" {
132142
}
133143

134144
name = each.key
135-
cdn_frontdoor_endpoint_id = azurerm_cdn_frontdoor_endpoint.fd_endpoints[each.value.frontend_endpoint].id
145+
cdn_frontdoor_endpoint_id = azurerm_cdn_frontdoor_endpoint.fd_endpoint.id
136146
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.fd_origin_groups[each.value.origin_group_name].id
137147
cdn_frontdoor_origin_ids = [azurerm_cdn_frontdoor_origin.fd_origins[each.value.origin_group_name].id]
138-
enabled = lookup(each.value, "enabled", true)
148+
cdn_frontdoor_custom_domain_ids = [azurerm_cdn_frontdoor_custom_domain.fd_custom_domains[each.value.custom_domain_name].id]
139149

140150
forwarding_protocol = "HttpsOnly"
141151
patterns_to_match = each.value.patterns_to_match
142152
supported_protocols = each.value.supported_protocols
143-
144-
cdn_frontdoor_custom_domain_ids = [azurerm_cdn_frontdoor_custom_domain.fd_custom_domains[each.value.frontend_endpoint].id]
153+
enabled = each.value.enabled
145154
link_to_default_domain = false
146155
}
147156

modules/azure/frontdoor_standard/variables.tf

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,17 @@ variable "name" {
1414
}
1515
}
1616

17-
variable "endpoints" {
18-
type = list(string)
19-
description = "List of frontend_endpoint names for frontdoor."
20-
21-
validation {
22-
condition = length(var.endpoints) > 0
23-
error_message = "The list with endpoints should at least contain one object."
24-
}
17+
variable "custom_domains" {
18+
type = list(object({
19+
name = string
20+
host_name = string
21+
}))
22+
description = "List of custom domains for frontdoor."
2523
}
26-
2724
variable "redirect_routes" {
2825
type = list(object({
2926
name = string
30-
frontend_endpoint = string
27+
custom_domain_name = string
3128
origin_group_name = string
3229
enabled = optional(bool)
3330
supported_protocols = list(string)

0 commit comments

Comments
 (0)