Skip to content

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.


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> 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:


Defines the URL visitors will use. Choose a name that reflects your brand or the app's purpose.

domain_name = ""

Changing this argument triggers the creation of a new custom domain resource.


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:


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  =
  domain_name     = ""
  validation_type = "cname-delegation"

In this example, 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.


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.