-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow passing a list of redirect rules per environment. Rules are triggered per domain and may: - redirect to domain on the same front door or external - redirect to the same path as in the incoming request - redirect to a specific path - add a query string Additional rule sets may still be passed using the rule_set_ids variable
- Loading branch information
Showing
3 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
resource "azurerm_cdn_frontdoor_rule_set" "redirects" { | ||
count = length(var.redirect_rules) > 0 ? 1 : 0 | ||
|
||
name = "${var.environment}Redirects" | ||
cdn_frontdoor_profile_id = data.azurerm_cdn_frontdoor_profile.main.id | ||
} | ||
|
||
resource "azurerm_cdn_frontdoor_rule" "rule" { | ||
count = length(var.redirect_rules) | ||
depends_on = [azurerm_cdn_frontdoor_origin_group.main, azurerm_cdn_frontdoor_origin.main] | ||
|
||
name = "rule${count.index}" | ||
cdn_frontdoor_rule_set_id = azurerm_cdn_frontdoor_rule_set.redirects[0].id | ||
order = count.index | ||
behavior_on_match = "Continue" | ||
|
||
conditions { | ||
host_name_condition { | ||
operator = "Equal" | ||
match_values = [for d in [var.redirect_rules[count.index]["from-domain"]] : d == "apex" ? "${var.zone}" : "${d}.${var.zone}"] | ||
} | ||
} | ||
|
||
actions { | ||
url_redirect_action { | ||
redirect_type = "Moved" | ||
redirect_protocol = "Https" | ||
destination_hostname = var.redirect_rules[count.index]["to-domain"] | ||
destination_path = try(var.redirect_rules[count.index]["to-path"], null) | ||
query_string = try(var.redirect_rules[count.index]["to-query-string"], null) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters