Skip to content

Commit bbd9a80

Browse files
authored
Merge pull request #227670 from TomArcherMsft/UserStory60501-azurerm_dns_zone
User Story 60501: azurerm_dns_zone
2 parents 44842a1 + d0ae82b commit bbd9a80

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

articles/dns/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
- name: Create a public zone - ARM Template
2626
displayName: Resource Manager
2727
href: dns-get-started-template.md
28+
- name: Create a public zone - Terraform
29+
href: dns-get-started-terraform.md
2830
- name: Private DNS
2931
items:
3032
- name: Create a private zone - portal
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
title: 'Quickstart: Create an Azure DNS zone and record using Terraform'
3+
description: 'In this article, you create an Azure DNS zone and record using Terraform'
4+
ms.topic: quickstart
5+
ms.service: dns
6+
ms.date: 3/16/2023
7+
ms.custom: devx-track-terraform
8+
author: TomArcherMsft
9+
ms.author: tarcher
10+
---
11+
12+
# Quickstart: Create an Azure DNS zone and record using Terraform
13+
14+
This article shows how to use [Terraform](/azure/terraform) to create an [Azure DNS zone](/azure/dns/dns-zones-records) and an [A record](/azure/dns/dns-alias) in that zone.
15+
16+
[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
17+
18+
In this article, you learn how to:
19+
20+
> [!div class="checklist"]
21+
> * Create a random pet name for the Azure resource group name using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
22+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
23+
> * Create a random string using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
24+
> * Create an Azure DNS zone using [azurerm_dns_zone](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dns_zone)
25+
> * Create an Azure DNS A record using [azurerm_dns_a_record](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dns_a_record)
26+
27+
[!INCLUDE [AI attribution](../../includes/ai-generated-attribution.md)]
28+
29+
## Prerequisites
30+
31+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
32+
33+
## Implement the Terraform code
34+
35+
> [!NOTE]
36+
> The example code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-dns_zone). See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
37+
38+
1. Create a directory in which to test and run the sample Terraform code and make it the current directory.
39+
40+
1. Create a file named `providers.tf` and insert the following code:
41+
42+
[!code-terraform[master](~/terraform_samples/quickstart/101-dns_zone/providers.tf)]
43+
44+
1. Create a file named `main.tf` and insert the following code:
45+
46+
[!code-terraform[master](~/terraform_samples/quickstart/101-dns_zone/main.tf)]
47+
48+
1. Create a file named `variables.tf` and insert the following code:
49+
50+
[!code-terraform[master](~/terraform_samples/quickstart/101-dns_zone/variables.tf)]
51+
52+
1. Create a file named `outputs.tf` and insert the following code:
53+
54+
[!code-terraform[master](~/terraform_samples/quickstart/101-dns_zone/outputs.tf)]
55+
56+
## Initialize Terraform
57+
58+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
59+
60+
## Create a Terraform execution plan
61+
62+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
63+
64+
## Apply a Terraform execution plan
65+
66+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
67+
68+
## Verify the results
69+
70+
#### [Azure CLI](#tab/azure-cli)
71+
72+
1. Get the Azure resource group name.
73+
74+
```console
75+
resource_group_name=$(terraform output -raw resource_group_name)
76+
```
77+
78+
1. Get the DNS zone name.
79+
80+
```console
81+
dns_zone_name=$(terraform output -raw dns_zone_name)
82+
```
83+
84+
1. Run [az network dns zone show](/cli/azure/network/dns/zone#az-network-dns-zone-show) to display information about the new DNS zone.
85+
86+
```azurecli
87+
az network dns zone show \
88+
--resource-group $resource_group_name \
89+
--name $dns_zone_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. Get the DNS zone name.
101+
102+
```console
103+
$dns_zone_name=$(terraform output -raw dns_zone_name)
104+
```
105+
106+
1. Run [Get-AzDnsZone](/powershell/module/az.dns/get-azdnszone) to display information about the new service.
107+
108+
```azurepowershell
109+
Get-AzDnsZone -ResourceGroupName $resource_group_name `
110+
-Name $dns_zone_name
111+
```
112+
113+
---
114+
115+
## Clean up resources
116+
117+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
118+
119+
## Troubleshoot Terraform on Azure
120+
121+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
122+
123+
## Next steps
124+
125+
> [!div class="nextstepaction"]
126+
> [Learn more about Azure DNS](/azure/dns)

0 commit comments

Comments
 (0)