Hi demo user,
Welcome to Microsoft Q&A and thank you for posting your query here!
Creating A records for VMs in Azure Private DNS zones using Azure Policy (DeployIfNotExists) is indeed possible but presents notable practical challenges and limitations, which can cause the errors you experienced such as:
- "No policy evaluation result was found" — often due to timing issues where the policy runs before the VM’s network interface (NIC) and private IP are queryable.
"ResourceNotFound" for existence conditions — when the DNS record name or resource is not matching exactly or available at the evaluation time.
Reference chaining (VM → NIC → Private IP) can fail if resources are not provisioned or accessible during policy evaluation.
Remediation tasks requiring ResourceDiscoveryMode set to ReEvaluateCompliance sometimes still don't resolve compliance due to scope or timing issues.
Key reasons for difficulties:
- The policy evaluates asynchronously after VM creation, meaning NIC and IP details may not be ready, breaking references.
- The DNS A record existence condition must precisely match naming conventions in the private DNS zone, including case sensitivity.
- The pure DeployIfNotExists effect in policy lacks instant or real-time registration and cannot automatically clean up records after VM deletion.
Recommended practical approach:
As you found, combining Azure Policy with custom automation scripts (PowerShell or shell) and the Azure REST API is the best reliable pattern:
- Use Azure Policy to detect non-compliant VMs (without DNS A records).
- Trigger an automated remediation task running a script with a Managed Identity having Private DNS Zone Contributor rights.
- This script queries the VM’s NIC to retrieve its private IP and creates/updates the corresponding A record using the Azure REST API.
- This hybrid method avoids the pitfalls of direct DeployIfNotExists ARM template references and improves control, logging, and error handling.
Additional recommendations:
- Verify the Managed Identity used in policy remediation has appropriate permissions on Private DNS zone resource groups.
- Carefully confirm that existence conditions in your policy accurately reflect your DNS naming scheme.
- Scope the policy assignment correctly to cover VMs or NICs as needed.
- Disable Azure VM auto-registration if you want full control through policy and automation.
- Always specify
ResourceDiscoveryModeasReEvaluateComplianceduring remediation to force policy re-evaluation. - Consider using Azure built-in policies or initiatives related to Private DNS and Private Link where applicable.
References for further study:
- Azure Policy definition structure and DeployIfNotExists effect: https://learn.microsoft.com/azure/governance/policy/concepts/definition-structure
- Troubleshooting ARM deployment errors such as ResourceNotFound: https://learn.microsoft.com/azure/azure-resource-manager/troubleshooting/common-deployment-errors
- Private DNS zone management best practices and records overview: https://learn.microsoft.com/azure/dns/private-dns-overview
Your solution using Azure Policy combined with scripts and API automation is the recommended path when you don’t want to rely on Azure VM auto-registration. This hybrid approach is flexible, reliable, and easier to maintain.
Feel free to reach out to us if you need any assistance on this!
If the information resolved your issue, kindly consider accepting the answer — it will help others who might be facing similar challenges.
Thanks,
Harish.