From 435d3ca70c1a6213a65e4e600cecceac62356679 Mon Sep 17 00:00:00 2001 From: Colin Saliceti Date: Wed, 11 Dec 2024 13:10:50 +0000 Subject: [PATCH] Allow 1 character custom domains length The name of the custom domain in front door is the same as the subdomain. Subdomain with 1 character is allowed but not the custom domain name. Add a fix to create a longer name when the subdomain is 1 character. This is required as the length of "." cannot exceed 64 characters and some subdomains must be 1 character to fit in. --- domains/environment_domains/front_door.tf | 2 +- domains/environment_domains/tfdocs.md | 2 +- domains/environment_domains/variables.tf | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/domains/environment_domains/front_door.tf b/domains/environment_domains/front_door.tf index 069910e..bbe0d30 100644 --- a/domains/environment_domains/front_door.tf +++ b/domains/environment_domains/front_door.tf @@ -33,7 +33,7 @@ resource "azurerm_cdn_frontdoor_origin" "main" { resource "azurerm_cdn_frontdoor_custom_domain" "main" { for_each = toset(var.domains) - name = replace(each.key, ".", "-") + name = length(each.key) > 1 ? replace(each.key, ".", "-") : "${replace(each.key, ".", "-")}-domain" cdn_frontdoor_profile_id = data.azurerm_cdn_frontdoor_profile.main.id dns_zone_id = data.azurerm_dns_zone.main.id host_name = startswith(each.key, "apex") ? var.zone : "${each.key}.${var.zone}" diff --git a/domains/environment_domains/tfdocs.md b/domains/environment_domains/tfdocs.md index 0f5c661..b6d73d2 100644 --- a/domains/environment_domains/tfdocs.md +++ b/domains/environment_domains/tfdocs.md @@ -40,7 +40,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [cached\_paths](#input\_cached\_paths) | List of path patterns such as /packs/* that front door will cache | `list(string)` | `[]` | no | -| [domains](#input\_domains) | List of subdomains of the zone e.g. "staging". For apex domain use "apex" or "apex" if apex is already in use | `any` | n/a | yes | +| [domains](#input\_domains) | List of subdomains of the zone e.g. "staging". For apex domain use "apex" or "apex" if apex is already in use.
The length of "." cannot exceed 64 characters. | `any` | n/a | yes | | [environment](#input\_environment) | n/a | `any` | n/a | yes | | [exclude\_cnames](#input\_exclude\_cnames) | Don't create the CNAME for this record from var.domains. We set this when we want to configure front door for a services domain that we are migrating so we do not need to wait for the certificate to validate and front door to propagate the configuration. | `list` | `[]` | no | | [front\_door\_name](#input\_front\_door\_name) | n/a | `any` | n/a | yes | diff --git a/domains/environment_domains/variables.tf b/domains/environment_domains/variables.tf index 023e8f2..3e910b9 100644 --- a/domains/environment_domains/variables.tf +++ b/domains/environment_domains/variables.tf @@ -3,7 +3,8 @@ variable "front_door_name" {} variable "resource_group_name" {} variable "domains" { description = <" if apex is already in use + List of subdomains of the zone e.g. "staging". For apex domain use "apex" or "apex" if apex is already in use. + The length of "." cannot exceed 64 characters. EOF } variable "environment" {}