Click on each book below to review & buy on Amazon.
As an Amazon Associate, I earn from qualifying purchases.
Terraform AzureRM - azurerm_static_site_custom_domain
Azure Static Web Apps provide a streamlined environment for hosting web applications, integrating source control, global distribution, and more. Custom domains personalize these apps, enhancing their professionalism and accessibility. This guide explores how to manage Azure Static Web Apps custom domains using Terraform, a popular infrastructure-as-code tool.
Prerequisite
Before configuring custom domains, ensure the Azure Static Web App is set up:
- Declare your
azurerm_static_site
resource. This resource is essential for hosting your web application on Azure. If needed, refer to the azurerm_static_site. - Create a CNAME record pointing to
<generated sub-domain>.azurestaticapps.net
. This step is critical for domain verification and involves updating your domain's DNS settings.
Declare Static Site Custom Domain
Resource Block
The resource block in Terraform defines the custom domain resource. The local name serves as an identifier within Terraform’s configuration.
resource "azurerm_static_site_custom_domain" "<local name>" {
// Configuration details here
}
Required Arguments
These arguments are essential for setting up your custom domain:
domain_name
Defines the URL visitors will use. Choose a name that reflects your brand or the app's purpose.
domain_name = "example.com"
Changing this argument triggers the creation of a new custom domain resource.
static_site_id
Connects the custom domain to your Azure Static Web App. Use the identifier from your azurerm_static_site
resource.
static_site_id = azurerm_static_site.<local name>.id
Modification of this argument results in a new custom domain resource.
Optional Arguments
These enhance your domain configuration:
validation_type
Choose between 'cname-delegation' and 'dns-txt-token' for domain validation. This selection influences how Terraform confirms the domain's association with your web app.
validation_type = "cname-delegation"
Example Declaration
An example setup might look like this:
resource "azurerm_static_site_custom_domain" "example_site_domain" {
static_site_id = azurerm_static_site.example_site.id
domain_name = "example.com"
validation_type = "cname-delegation"
}
In this example, example.com
is linked to the example_site
static site using CNAME delegation for domain validation.
Additional Considerations
- SSL/TLS Certification: Azure automatically provisions and renews SSL/TLS certificates for custom domains, ensuring secure connections.
- Propagation Delay: DNS changes may take up to 48 hours to propagate globally. During this time, the domain may not be immediately accessible.
- Custom Domain Limitations: Be aware of any limits on the number of custom domains per static site, as dictated by your Azure subscription plan.
Conclusion
Integrating custom domains with Azure Static Web Apps elevates their professional presence. Through Terraform, this process becomes manageable and scalable, fitting seamlessly into a broader infrastructure-as-code strategy. This guide outlines the key steps and considerations for a successful custom domain setup on Azure using Terraform.
Support DTV Linux
Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.
NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.