|
| 1 | +--- |
| 2 | +title: 'Quickstart: Create an Azure DNS Private Resolver using Terraform' |
| 3 | +description: In this quickstart, you learn how to use Terraform to create and manage an Azure DNS Private Resolver. |
| 4 | +ms.topic: quickstart |
| 5 | +ms.date: 02/18/2025 |
| 6 | +ms.custom: devx-track-terraform |
| 7 | +ms.service: azure-dns |
| 8 | +author: greg-lindsay |
| 9 | +ms.author: greglin |
| 10 | +#customer intent: As a Terraform user, I want to learn how to use Terraform to create and manage an Azure DNS Private Resolver. |
| 11 | +content_well_notification: |
| 12 | + - AI-contribution |
| 13 | +--- |
| 14 | + |
| 15 | +# Quickstart: Create an Azure DNS Private Resolver using Terraform |
| 16 | + |
| 17 | +This quickstart describes how to use Terraform to create an Azure DNS Private Resolver. Azure private DNS resolver is a service that provides custom domain name resolution for your private Azure network. It's used to resolve domain names in a virtual network without needing to add a custom DNS solution. The resources created include the Azure DNS Private Resolver, a virtual network, and a subnet. The DNS resolver is associated with the virtual network, and the subnet is configured with a delegation to the DNS Private Resolver service. |
| 18 | + |
| 19 | +[!INCLUDE [About Terraform](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)] |
| 20 | + |
| 21 | +The following figure summarizes the general setup used. Subnet address ranges used in templates are slightly different than those shown in the figure. |
| 22 | + |
| 23 | +:::image type="content" source="./media/dns-resolver-getstarted-portal/resolver-components.png" alt-text="Conceptual figure displaying components of the private resolver." lightbox="./media/dns-resolver-getstarted-portal/resolver-components.png"::: |
| 24 | + |
| 25 | +> [!div class="checklist"] |
| 26 | +> * Create an Azure resource group with a unique name. |
| 27 | +> * Establish an Azure virtual network within the created resource group. |
| 28 | +> * Define a subnet within the virtual network, and delegate DNS Private Resolver service to it. |
| 29 | +> * Set up DNS Private Resolver within the resource group, and associate it with the virtual network. |
| 30 | +> * View DNS Private Resolver within the resource group. |
| 31 | +
|
| 32 | +## Prerequisites |
| 33 | + |
| 34 | +- If you don't have an Azure account, [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 35 | + |
| 36 | +- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure). |
| 37 | + |
| 38 | +## Implement the Terraform code |
| 39 | + |
| 40 | +> [!NOTE] |
| 41 | +> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-dns-private-resolver). You can view the log file containing the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/tree/master/quickstart/101-dns-private-resolver/TestRecord.md). |
| 42 | +> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform). |
| 43 | +
|
| 44 | +1. Create a directory in which to test and run the sample Terraform code, and make it the current directory. |
| 45 | + |
| 46 | +1. Create a file named `main.tf`, and insert the following code: |
| 47 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-dns-private-resolver/main.tf"::: |
| 48 | + |
| 49 | +1. Create a file named `outputs.tf`, and insert the following code: |
| 50 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-dns-private-resolver/outputs.tf"::: |
| 51 | + |
| 52 | +1. Create a file named `providers.tf`, and insert the following code: |
| 53 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-dns-private-resolver/providers.tf"::: |
| 54 | + |
| 55 | +1. Create a file named `variables.tf`, and insert the following code: |
| 56 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-dns-private-resolver/variables.tf"::: |
| 57 | + |
| 58 | +## Initialize Terraform |
| 59 | + |
| 60 | +[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)] |
| 61 | + |
| 62 | +## Create a Terraform execution plan |
| 63 | + |
| 64 | +[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)] |
| 65 | + |
| 66 | +## Apply a Terraform execution plan |
| 67 | + |
| 68 | +[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)] |
| 69 | + |
| 70 | +## Verify the results |
| 71 | + |
| 72 | +### [Azure CLI](#tab/azure-cli) |
| 73 | + |
| 74 | +1. Get the Azure resource group name. |
| 75 | + |
| 76 | + ```console |
| 77 | + resource_group_name=$(terraform output -raw resource_group_name) |
| 78 | + ``` |
| 79 | + |
| 80 | +1. Run `az network dns record-set list` to view the DNS Private Resolver service. |
| 81 | + |
| 82 | + ```azurecli |
| 83 | + az network dns record-set list --output table |
| 84 | + ``` |
| 85 | + |
| 86 | +1. Run `az network private-dns zone show` to view the DNS Private Resolver service within the resource group. |
| 87 | + |
| 88 | + ```azurecli |
| 89 | + az network private-dns zone show --name $private_dns_zone_name --resource-group $resource_group_name |
| 90 | + ``` |
| 91 | +
|
| 92 | +### [Azure PowerShell](#tab/azure-powershell) |
| 93 | +
|
| 94 | +1. Get the Azure resource group name. |
| 95 | +
|
| 96 | + ```console |
| 97 | + $resource_group_name=$(terraform output -raw resource_group_name) |
| 98 | + ``` |
| 99 | +
|
| 100 | +1. Run `Get-AzDnsRecordSet` to view the DNS Private Resolver service. |
| 101 | +
|
| 102 | + ```azurepowershell |
| 103 | + Get-AzDnsRecordSet -ZoneName $private_dns_zone_name -ResourceGroupName $resource_group_name | Format-Table |
| 104 | + ``` |
| 105 | +
|
| 106 | +1. Run `Get-AzPrivateDnsZone` to view the DNS Private Resolver service within the resource group. |
| 107 | +
|
| 108 | + ```azurepowershell |
| 109 | + Get-AzPrivateDnsZone -Name $private_dns_zone_name -ResourceGroupName $resource_group_name |
| 110 | + ``` |
| 111 | +
|
| 112 | +--- |
| 113 | +
|
| 114 | +## Clean up resources |
| 115 | +
|
| 116 | +[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)] |
| 117 | +
|
| 118 | +## Troubleshoot Terraform on Azure |
| 119 | +
|
| 120 | +[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot). |
| 121 | +
|
| 122 | +## Next steps |
| 123 | +
|
| 124 | +> [!div class="nextstepaction"] |
| 125 | +> [See more articles about Azure DNS Private Resolver](/search/?terms=Azure%20private%20dns%20resolver%20and%20terraform). |
0 commit comments