Terraform · azurerm provider

Terraform after the Front Door (classic) migration: from azurerm_frontdoor to azurerm_cdn_frontdoor_*

Microsoft's migration tool moves a classic Front Door to Standard or Premium without downtime. It doesn't touch your Terraform. This is how we map the old resource to the new ones, bring them into state with import blocks, and stop Terraform from destroying or rebuilding anything on the way.

What the migration leaves in your state

The tool works on the control plane only (Microsoft: tier migration). When you commit, the classic profile is disabled, the new Standard or Premium profile goes live, and the classic resource moves to a Migrated state where it no longer accepts changes. Your state file still holds one large azurerm_frontdoor resource of type Microsoft.Network/frontDoors. The live configuration now sits under Microsoft.Cdn/profiles, split into a dozen smaller resources.

Three things follow from that.

  • Any apply that touches azurerm_frontdoor after the commit tries to change a resource that can't be changed. The azurerm docs say changes to existing classic resources work only "until the API reaches full retirement on March 31, 2027" (azurerm_frontdoor).
  • The new resources exist in Azure but not in state. Write azurerm_cdn_frontdoor_* blocks and apply them without importing, and Terraform plans to create everything from scratch.
  • Microsoft's guide says that if you migrate with PowerShell, the CLI, the API or Terraform, you have to create the WAF policies yourself. The portal flow copies them for you.

Microsoft's own advice for Terraform is short: export the new configuration with Azure Export for Terraform, replace the classic references, run plan and apply (post-migration DevOps experience). That works. What follows is what we add so the first plan after the switch is boring.

How the resources map

On the classic side you have one resource with nested blocks. On Standard and Premium every object is its own resource. The table is based on Microsoft's settings mapping and the azurerm resource docs.

Classic (azurerm)Standard / Premium (azurerm)Notes
azurerm_frontdoorazurerm_cdn_frontdoor_profilesku_name is Standard_AzureFrontDoor or Premium_AzureFrontDoor. Changing it forces a new resource.
frontend_endpoint on *.azurefd.netazurerm_cdn_frontdoor_endpointThe new host name has a hash in it: <endpointname>-<hash>.z01.azurefd.net.
frontend_endpoint with a custom host_nameazurerm_cdn_frontdoor_custom_domain, linked through the route's cdn_frontdoor_custom_domain_ids or azurerm_cdn_frontdoor_custom_domain_associationStandard and Premium require HTTPS on every custom domain.
azurerm_frontdoor_custom_https_configurationtls block on the custom domain, plus azurerm_cdn_frontdoor_secret for your own certificateYour own certificate needs managed identity access to Key Vault.
backend_poolazurerm_cdn_frontdoor_origin_groupBackend pool becomes origin group.
backend inside a poolazurerm_cdn_frontdoor_originOne resource per origin.
backend_pool_health_probe, backend_pool_load_balancinghealth_probe and load_balancing blocks on the origin group
session_affinity_enabled on frontend_endpointsession_affinity_enabled on the origin groupSession affinity moved from the domain to the origin group.
routing_rule (forward)azurerm_cdn_frontdoor_routeCustom forwarding path becomes the origin path when URL rewrite was on.
routing_rule (redirect)azurerm_cdn_frontdoor_rule_set and azurerm_cdn_frontdoor_rule with a url_redirect actionThe tool creates a rule set called URLRedirectMigratedRuleSet1.
azurerm_frontdoor_rules_engineazurerm_cdn_frontdoor_rule_set and azurerm_cdn_frontdoor_ruleKeeps its association with the routes.
azurerm_frontdoor_firewall_policy and web_application_firewall_policy_link_idazurerm_cdn_frontdoor_firewall_policy and azurerm_cdn_frontdoor_security_policyThe WAF link moves from the domain into a security policy.

Names come from the migration, not from your code

The tool picks the names. The profile defaults to <endpointprefix>-migrated and WAF policies get -standard or -premium appended; you can rename both during migration. Rules engine configurations and routes get default names that you can't change during migration, and URL redirect and rewrite rules turn into rule set rules named urlRedirectMigrated and urlRewriteMigrated (naming convention).

In azurerm, changing name forces a new resource on the endpoint, origin group, origin, route, rule set and custom domain. So if your code keeps the old names, the first plan shows a replacement for each one. Take the names from the migrated profile, or from the exported code, and rename later as a planned change if you really want to.

Step by step

  1. Freeze applies on the classic stack. Once the prepare phase starts you can't change the classic configuration anyway, and a pipeline that tries will just fail.
  2. Migrate and commit. Review the read-only view of the new profile during prepare. After the commit there is no rollback.
  3. Take the classic resources out of state without destroying them. With a removed block, Terraform drops the resource from state and leaves the real thing alone when destroy = false (HashiCorp: removed block).
removed {
  from = azurerm_frontdoor.main
  lifecycle {
    destroy = false
  }
}

removed {
  from = azurerm_frontdoor_firewall_policy.main
  lifecycle {
    destroy = false
  }
}

Microsoft's FAQ says to delete the classic resource once migration completes. The classic hostname keeps serving traffic for the new profile until 31 March 2028, and the docs don't say how deleting the classic resource affects that. So we repoint DNS and clients first and delete afterwards. Details in what happens to the classic azurefd.net endpoint.

  1. Write the new code. Azure Export for Terraform gives you a full starting point. We usually fold its output into the module layout the team already has, and use the export to check every argument.
  2. Import with import blocks. They live in code, go through review, and show up in plan before anything changes (HashiCorp: import block). If you only write the import blocks, terraform plan -generate-config-out=generated.tf writes the resource blocks for you (HashiCorp: import).
import {
  to = azurerm_cdn_frontdoor_profile.main
  id = "/subscriptions/<sub-id>/resourceGroups/rg-edge/providers/Microsoft.Cdn/profiles/myfd-migrated"
}

import {
  to = azurerm_cdn_frontdoor_route.web
  id = "/subscriptions/<sub-id>/resourceGroups/rg-edge/providers/Microsoft.Cdn/profiles/myfd-migrated/afdEndpoints/myfd/routes/<route-name>"
}

import {
  to = azurerm_cdn_frontdoor_firewall_policy.main
  id = "/subscriptions/<sub-id>/resourceGroups/rg-edge/providers/Microsoft.Network/frontDoorWebApplicationFirewallPolicies/<policy-copy-name>"
}
  1. Read the plan. The target is no changes. Anything else is a gap between your code and the live profile. Fix the code, not Azure.
  2. Add diagnostics in the same change. Logs and metrics don't migrate, and the log fields differ from classic. Diagnostic logging on the new profile is off until you turn it on.

Gotchas in the azurerm provider

  • Routes need an explicit link to their origins. Every route needs either cdn_frontdoor_origin_ids or a depends_on on the origins. The field isn't sent to Azure; Terraform uses it to order create and destroy. After importing a route you have to add one of them by hand.
  • Rules need depends_on on the origin and the origin group, per the rule docs.
  • sku_name forces a new resource on both the profile and the firewall policy. If someone upgrades Standard to Premium in the portal, change the code before the next plan or you'll see a replacement.
  • The WAF resource type stays the same. azurerm_cdn_frontdoor_firewall_policy imports from Microsoft.Network/frontDoorWebApplicationFirewallPolicies, the same type the classic policy uses. Import the copy the migration made (the one ending in -standard or -premium), not the old policy.
  • A Standard WAF policy holds custom rules only. Managed rules need Premium_AzureFrontDoor. If that decision is still open, read Front Door Standard vs Premium before you write the code.

A route and a security policy for a migrated profile look like this:

resource "azurerm_cdn_frontdoor_route" "web" {
  name                          = "<route-name-from-migration>"
  cdn_frontdoor_endpoint_id     = azurerm_cdn_frontdoor_endpoint.main.id
  cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.web.id
  cdn_frontdoor_origin_ids      = [azurerm_cdn_frontdoor_origin.web.id]
  cdn_frontdoor_custom_domain_ids = [azurerm_cdn_frontdoor_custom_domain.www.id]
  patterns_to_match             = ["/*"]
  supported_protocols           = ["Http", "Https"]
}

resource "azurerm_cdn_frontdoor_security_policy" "waf" {
  name                     = "waf"
  cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.main.id

  security_policies {
    firewall {
      cdn_frontdoor_firewall_policy_id = azurerm_cdn_frontdoor_firewall_policy.main.id

      association {
        domain {
          cdn_frontdoor_domain_id = azurerm_cdn_frontdoor_custom_domain.www.id
        }
        patterns_to_match = ["/*"]
      }
    }
  }
}

If outputs or app settings in your code still hold the classic *.azurefd.net name, point them at azurerm_cdn_frontdoor_endpoint.main.host_name instead. That's the name that keeps working after March 2028.

Same job for Azure CDN (classic)

If you also run azurerm_cdn_profile and azurerm_cdn_endpoint, the target resources are the same azurerm_cdn_frontdoor_* set. The CDN case differs in a useful way: the profile keeps its name and resource ID. The Azure CDN (classic) exit checklist covers it.

Need it done for a fixed price? Start with a free Readiness Check

We review the classic setup and your Terraform, then give you a written migration plan and a fixed quote before anything changes. More on the service: Azure Front Door (classic) migration.

Sources: Microsoft: Front Door (classic) to Standard/Premium tier migration · Microsoft: settings mapping · Microsoft: post-migration DevOps experience · Microsoft: Front Door (classic) retirement FAQ · azurerm_frontdoor · azurerm_cdn_frontdoor_profile · azurerm_cdn_frontdoor_route · azurerm_cdn_frontdoor_rule · azurerm_cdn_frontdoor_firewall_policy · azurerm_cdn_frontdoor_security_policy · HashiCorp: import block · HashiCorp: removed block. Last reviewed 12 November 2026.