|
| 1 | +--- |
| 2 | +title: 'Quickstart: Use Terraform to configure private DNS zones in Azure' |
| 3 | +description: In this quickstart, you create a private DNS zone, network interfaces, Windows virtual machines, a private DNS A record, network security groups, and a network security rule in Azure. |
| 4 | +ms.topic: quickstart |
| 5 | +ms.date: 2/19/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 see how to create a private DNS zone and Windows virtual machines in Azure. |
| 11 | +content_well_notification: |
| 12 | + - AI-contribution |
| 13 | +--- |
| 14 | + |
| 15 | +# Quickstart: Use Terraform to configure private DNS zones in Azure |
| 16 | + |
| 17 | +In this quickstart, you use Terraform to create private DNS zones, network interfaces, Windows virtual machines, a private DNS A record, network security groups, and a network security rule in Azure. |
| 18 | + |
| 19 | +[!INCLUDE [About Terraform](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)] |
| 20 | + |
| 21 | +> [!div class="checklist"] |
| 22 | +> * Create an Azure resource group with a unique name. |
| 23 | +> * Establish a virtual network with a specified name and address. |
| 24 | +> * Set up a subnet within the created virtual network. |
| 25 | +> * Create a private DNS zone. |
| 26 | +> * Generate random passwords for the virtual machines. |
| 27 | +> * Create two network interfaces. |
| 28 | +> * Create two Windows virtual machines, and attach the network interfaces. |
| 29 | +> * Create a private DNS A record. |
| 30 | +> * Create a network security group and a network security rule to allow ICMP traffic. |
| 31 | +> * Output the names and admin credentials of the virtual machines. |
| 32 | +
|
| 33 | +## Prerequisites |
| 34 | + |
| 35 | +- Create an Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). |
| 36 | + |
| 37 | +- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure). |
| 38 | + |
| 39 | +## Implement the Terraform code |
| 40 | + |
| 41 | +> [!NOTE] |
| 42 | +> 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-zone). 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-zone/TestRecord.md). |
| 43 | +> |
| 44 | +> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform). |
| 45 | +
|
| 46 | +1. Create a directory in which to test and run the sample Terraform code, and make it the current directory. |
| 47 | + |
| 48 | +1. Create a file named `main.tf`, and insert the following code: |
| 49 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-dns-private-zone/main.tf"::: |
| 50 | + |
| 51 | +1. Create a file named `outputs.tf`, and insert the following code: |
| 52 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-dns-private-zone/outputs.tf"::: |
| 53 | + |
| 54 | +1. Create a file named `providers.tf`, and insert the following code: |
| 55 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-dns-private-zone/providers.tf"::: |
| 56 | + |
| 57 | +1. Create a file named `variables.tf`, and insert the following code: |
| 58 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-dns-private-zone/variables.tf"::: |
| 59 | + |
| 60 | +## Initialize Terraform |
| 61 | + |
| 62 | +[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)] |
| 63 | + |
| 64 | +## Create a Terraform execution plan |
| 65 | + |
| 66 | +[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)] |
| 67 | + |
| 68 | +## Apply a Terraform execution plan |
| 69 | + |
| 70 | +[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)] |
| 71 | + |
| 72 | +## Verify the results |
| 73 | + |
| 74 | +### [Azure CLI](#tab/azure-cli) |
| 75 | + |
| 76 | +1. Run `az network private-dns zone list` to view all DNS zones and find yours. |
| 77 | + |
| 78 | + ```azurecli |
| 79 | + az network private-dns zone list --output table |
| 80 | + ``` |
| 81 | + |
| 82 | +1. Run `az network private-dns zone show` to view the resource group associate with your DNS zone. |
| 83 | + |
| 84 | + ```azurecli |
| 85 | + az network private-dns zone show --name $dnsZoneName --resource-group $resourceGroupName |
| 86 | + ``` |
| 87 | + |
| 88 | +### [Azure PowerShell](#tab/azure-powershell) |
| 89 | + |
| 90 | +1. Run `Get-AzPrivateDnsZone` to view all DNS zones and find yours. |
| 91 | + |
| 92 | + ```azurepowershell |
| 93 | + Get-AzPrivateDnsZone | Format-Table |
| 94 | + ``` |
| 95 | +
|
| 96 | +2. Run `Get-AzPrivateDnsZone` to view the resource group associated with your DNS zone. |
| 97 | +
|
| 98 | + ```azurepowershell |
| 99 | + Get-AzPrivateDnsZone -Name $dnsZoneName -ResourceGroupName $resourceGroupName |
| 100 | + ``` |
| 101 | +
|
| 102 | +--- |
| 103 | +
|
| 104 | +## Clean up resources |
| 105 | +
|
| 106 | +[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)] |
| 107 | +
|
| 108 | +## Troubleshoot Terraform on Azure |
| 109 | +
|
| 110 | +[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot). |
| 111 | +
|
| 112 | +## Next steps |
| 113 | +
|
| 114 | +> [!div class="nextstepaction"] |
| 115 | +> [See more articles about Azure DNS zones](/search/?terms=Azure%20dns%20zones%20and%20terraform). |
0 commit comments