How Can I add A record PriateDNS zones, for VM that is created in same DNZ zone

demo user 20 Reputation points
2025-10-09T05:34:14.16+00:00

Creation of Azure Policy creation to deploy private DNS records for virtual machines in private DNS zones

  • Write a policy that automatically deploys a private DNS record for virtual machines (effect DeployIfNotExists)
  • The created DNS record will be an A record that points to the VM’s private IP address

Is this really possible
We dont want to use Auto Registration feature available in Azure and only want to do Azure Policy way

Azure DNS
Azure DNS
An Azure service that enables hosting Domain Name System (DNS) domains in Azure.
{count} votes

Answer accepted by question author
  1. Harish Peddapally 1,670 Reputation points Microsoft External Staff Moderator
    2025-10-23T07:29:42.3066667+00:00

    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 ResourceDiscoveryMode as ReEvaluateCompliance during 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:

    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.