Quickstart: Create an Azure DNS zone and record using an ARM template

This quickstart describes how to use an Azure Resource Manager template (ARM Template) to create a DNS zone with an A record in it.

An Azure Resource Manager template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. You describe your intended deployment without writing the sequence of programming commands to create the deployment.

If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.

Button to deploy the Resource Manager template to Azure.

Prerequisites

If you don't have an Azure subscription, create a free account before you begin.

Review the template

The template used in this quickstart is from Azure Quickstart Templates.

In this quickstart, you'll create a unique DNS zone with a suffix of azurequickstart.org. An A record pointing to two IP addresses will also be placed in the zone.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.8.9.13224",
      "templateHash": "3207741835848035910"
    }
  },
  "parameters": {
    "zoneName": {
      "type": "string",
      "defaultValue": "[format('{0}.azurequickstart.org', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "The name of the DNS zone to be created.  Must have at least 2 segments, e.g. hostname.org"
      }
    },
    "recordName": {
      "type": "string",
      "defaultValue": "www",
      "metadata": {
        "description": "The name of the DNS record to be created.  The name is relative to the zone, not the FQDN."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Network/dnsZones",
      "apiVersion": "2018-05-01",
      "name": "[parameters('zoneName')]",
      "location": "global"
    },
    {
      "type": "Microsoft.Network/dnsZones/A",
      "apiVersion": "2018-05-01",
      "name": "[format('{0}/{1}', parameters('zoneName'), parameters('recordName'))]",
      "properties": {
        "TTL": 3600,
        "ARecords": [
          {
            "ipv4Address": "1.2.3.4"
          },
          {
            "ipv4Address": "1.2.3.5"
          }
        ]
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/dnsZones', parameters('zoneName'))]"
      ]
    }
  ],
  "outputs": {
    "nameServers": {
      "type": "array",
      "value": "[reference(resourceId('Microsoft.Network/dnsZones', parameters('zoneName'))).nameServers]"
    }
  }
}

Two Azure resources have been defined in the template:

To find more templates that are related to Azure Traffic Manager, see Azure Quickstart Templates.

Deploy the template

  1. Select Try it from the following code block to open Azure Cloud Shell, and then follow the instructions to sign in to Azure.

    $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
    $location = Read-Host -Prompt "Enter the location (i.e. centralus)"
    $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.network/azure-dns-new-zone/azuredeploy.json"
    
    $resourceGroupName = "${projectName}rg"
    
    New-AzResourceGroup -Name $resourceGroupName -Location "$location"
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri
    
    Read-Host -Prompt "Press [ENTER] to continue ..."
    

    Wait until you see the prompt from the console.

  2. Select Copy from the previous code block to copy the PowerShell script.

  3. Right-click the shell console pane and then select Paste.

  4. Enter the values.

    The template deployment creates a zone with one A record pointing to two IP addresses. The resource group name is the project name with rg appended.

    It takes a couple seconds to deploy the template. When completed, the output is similar to:

    Azure DNS zone Resource Manager template PowerShell deployment output

Azure PowerShell is used to deploy the template. In addition to Azure PowerShell, you can also use the Azure portal, Azure CLI, and REST API. To learn other deployment methods, see Deploy templates.

Validate the deployment

  1. Sign in to the Azure portal.

  2. Select Resource groups from the left pane.

  3. Select the resource group that you created in the previous section. The default resource group name is the project name with rg appended.

  4. The resource group should contain the following resources seen here:

    DNS zone deployment resource group

  5. Select the DNS zone with the suffix of azurequickstart.org to verify that the zone is created properly with an A record referencing the value of 1.2.3.4 and 1.2.3.5.

    DNS zone deployment

  6. Copy one of the name server names from the previous step.

  7. Open a command prompt, and run the following command:

    nslookup www.<dns zone name> <name server name>
    

    For example:

    nslookup www.2lwynbseszpam.azurequickstart.org ns1-09.azure-dns.com.
    

    You should see something like the following screenshot:

    DNS zone nslookup

The host name www.2lwynbseszpam.azurequickstart.org resolves to 1.2.3.4 and 1.2.3.5, just as you configured it. This result verifies that name resolution is working correctly.

Clean up resources

When you no longer need the resources that you created with the DNS zone, delete the resource group. This action removes the DNS zone and all the related resources.

To delete the resource group, call the Remove-AzResourceGroup cmdlet:

Remove-AzResourceGroup -Name <your resource group name>

Next steps

In this quickstart, you created a:

  • DNS zone
  • A record

Now that you've created your first DNS zone and record using an ARM template, you can create records for a web app in a custom domain.