How to Add new VM into Custom Linux DNS server through ARM Template

Ashok Kumar Jayabalan 0 Reputation points
2024-07-23T05:34:53.6633333+00:00

Hello,

We are using ansible for creating Azure VMs and adding the DNS records of Azure VM into the Custom Linux DNS server. Not Azure DNS.

Now migrating into ARM template for Azure VM creation. Is that any way to create A record into the Linux DNS server from ARM template ?

dns_host:  "hostname"
dns_zone:  ""

dns_type:  "A"

dns_IP:  "host_ip'"

Now migrating into ARM template for Azure VM creation.

Is that any way to create A record into the Linux DNS server from ARM template ? Thanks,

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,566 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 7,286 Reputation points
    2024-07-23T21:18:51.61+00:00

    Hello Ashok Kumar Jayabalan,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Problem

    I understand that you would like to add a new Azure VM into a custom Linux DNS server using an ARM (Azure Resource Manager) template, and to add an A record to your Linux DNS server.

    Solution

    To resolve this issue, I would want to believe that your ARM template defines your VM’s infrastructure. Include the necessary resources like the VM, network interfaces, and storage and in your ARM template, add a custom script extension to the VM resource. The extension will run a script on the VM after deployment, it will modify the /etc/hosts file on the VM to include the desired A record (hostname and IP address). What I can lay my hand on right now as an example for best practices is as follows:

    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "name": "customScript",
      "apiVersion": "2021-04-01",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
      ],
      "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "typeHandlerVersion": "2.1",
        "settings": {
          "script": "echo 'host_ip hostname' >> /etc/hosts"
        }
      }
    }
    

    So, deploy your ARM template using the Azure CLI, PowerShell, or the Azure portal, the custom script extension will execute during VM provisioning and update the /etc/hosts file. But don't forget to adapt the script and template parameters to match your environment.

    References

    Accept Answer

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam

    0 comments No comments