The Microsoft documentation explains what happens during failover but not how to automate DNS updates using Azure Policy, because Azure Policy is not designed to perform resource updates or runtime automation tasks like DNS record changes. Azure Policy is a compliance and governance tool, not an automation tool. It evaluates resources at creation or modification time, not during failover. Policies can, for example, audit if a private DNS zone exists or has a required A record, deny deployment if criteria are not met, but not update or change DNS records when failover happens.
To handle automatic DNS updates after a failover event, consider this automation plan using Azure-native tools:
- Detect failover
Use Azure Resource Graph, Azure Monitor alert, or log-based queries to detect a failover. This could be:
- Blob Storage
serviceStats
or health metrics. - Event Grid (if you have a health probe monitoring solution).
- Or use
Get-AzStorageAccountFailoverReplicationPolicyStatus
periodically.
- Trigger Automation runbook or Logic App
When failover is detected trigger an Azure Automation Runbook, Logic App, or Function App.
- Update the DNS mapping
In the runbook or function:
- Use PowerShell or Azure CLI to:
- Get the new private IP of the secondary endpoint.
- Update the A record in the private DNS zone.
# Example PowerShell snippet
$dnsZone = "privatelink.blob.core.windows.net"
$recordName = "<storageaccountname>"
$resourceGroup = "<dns-zone-resource-group>"
# Get private endpoint IP
$privateEndpoint = Get-AzPrivateEndpoint -Name "<secondary-endpoint-name>" -ResourceGroupName "<resource-group>"
$ip = $privateEndpoint.CustomDnsConfigs[0].IpAddresses[0]
# Update A record
Remove-AzPrivateDnsRecordSet -Name $recordName -ZoneName $dnsZone -ResourceGroupName $resourceGroup -Force
New-AzPrivateDnsRecordSet -Name $recordName -ZoneName $dnsZone -ResourceGroupName $resourceGroup -RecordType A -Ttl 3600 -DnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $ip)
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin