Skip to content

Commit 411759b

Browse files
committed
Quickstart using Terraform
1 parent 796ed92 commit 411759b

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed

articles/ddos-protection/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
displayName: Resource Manager
2525
href: manage-ddos-protection-template.md
2626
expanded: true
27+
- name: Terraform
28+
href: manage-ddos-protection-terraform.md
2729
- name: DDoS IP Protection
2830
items:
2931
- name: Portal
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
title: 'Quickstart: Create and configure Azure DDoS Network Protection using Terraform'
3+
description: In this article, you create and configure Azure DDoS Network Protection using Terraform
4+
author: TomArcherMsft
5+
ms.service: ddos-protection
6+
ms.topic: quickstart
7+
ms.workload: infrastructure-services
8+
ms.custom: devx-track-terraform
9+
ms.author: tarcher
10+
ms.date: 4/12/2023
11+
---
12+
13+
# Quickstart: Create and configure Azure DDoS Network Protection using Terraform
14+
15+
This quickstart describes how to use Terraform to create and enable a [distributed denial of service (DDoS) protection plan](ddos-protection-overview) and [Azure virtual network (VNet)](/azure/virtual-network/virtual-networks-overview). An Azure DDoS Network Protection plan defines a set of virtual networks that have DDoS protection enabled across subscriptions. You can configure one DDoS protection plan for your organization and link virtual networks from multiple subscriptions to the same plan.
16+
17+
[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
18+
19+
In this article, you learn how to:
20+
21+
> [!div class="checklist"]
22+
> * Create a random value for the Azure resource group name using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
23+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
24+
> * Create a random value for the virtual network name using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
25+
> * Create an Azure DDoS protection plan using [azurerm_network_ddos_protection_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_ddos_protection_plan)
26+
> * Create an Azure virtual network using [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network)
27+
28+
[!INCLUDE [AI attribution](../../includes/ai-generated-attribution.md)]
29+
30+
## Prerequisites
31+
32+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
33+
34+
## Implement the Terraform code
35+
36+
> [!NOTE]
37+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-ddos-protection-plan). 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-ddos-protection-plan/TestRecord.md).
38+
>
39+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
40+
41+
1. Create a directory in which to test and run the sample Terraform code and make it the current directory.
42+
43+
1. Create a file named `providers.tf` and insert the following code:
44+
45+
[!code-terraform[master](~/terraform_samples/quickstart/101-ddos-protection-plan/providers.tf)]
46+
47+
1. Create a file named `main.tf` and insert the following code:
48+
49+
[!code-terraform[master](~/terraform_samples/quickstart/101-ddos-protection-plan/main.tf)]
50+
51+
1. Create a file named `variables.tf` and insert the following code:
52+
53+
[!code-terraform[master](~/terraform_samples/quickstart/101-ddos-protection-plan/variables.tf)]
54+
55+
1. Create a file named `outputs.tf` and insert the following code:
56+
57+
[!code-terraform[master](~/terraform_samples/quickstart/101-ddos-protection-plan/outputs.tf)]
58+
59+
## Initialize Terraform
60+
61+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
62+
63+
## Create a Terraform execution plan
64+
65+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
66+
67+
## Apply a Terraform execution plan
68+
69+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
70+
71+
## Verify the results
72+
73+
#### [Azure CLI](#tab/azure-cli)
74+
75+
1. Get the Azure resource group name.
76+
77+
```console
78+
resource_group_name=$(terraform output -raw resource_group_name)
79+
```
80+
81+
1. Get the DDoS protection plan name.
82+
83+
```console
84+
ddos_protection_plan_name=$(terraform output -raw ddos_protection_plan_name)
85+
```
86+
87+
1. Run [az network ddos-protection show](/cli/azure/network/ddos-protection#az-network-ddos-protection-show) to display information about the new DDoS protection plan.
88+
89+
```azurecli
90+
az network ddos-protection show \
91+
--resource-group $resource_group_name \
92+
--name $ddos_protection_plan_name
93+
```
94+
95+
#### [Azure PowerShell](#tab/azure-powershell)
96+
97+
1. Get the Azure resource group name.
98+
99+
```console
100+
$resource_group_name=$(terraform output -raw resource_group_name)
101+
```
102+
103+
1. Get the DDoS protection plan name.
104+
105+
```console
106+
$ddos_protection_plan_name=$(terraform output -raw ddos_protection_plan_name)
107+
```
108+
109+
1. Run [Get-AzDdosProtectionPlan](/powershell/module/az.network/get-azddosprotectionplan) to display information about the new DDoS protection plan.
110+
111+
```azurepowershell
112+
Get-AzDdosProtectionPlan -ResourceGroupName $resource_group_name `
113+
-Name $ddos_protection_plan_name
114+
```
115+
116+
1. Get the virtual network name.
117+
118+
```console
119+
$virtual_network_name=$(terraform output -raw virtual_network_name)
120+
```
121+
122+
1. Run [Get-AzVirtualNetwork](/powershell/module/az.network/get-azvirtualnetwork) to display information about the new virtual network.
123+
124+
```azurepowershell
125+
Get-AzVirtualNetwork -ResourceGroupName $resource_group_name `
126+
-Name $virtual_network_name
127+
```
128+
129+
---
130+
131+
## Clean up resources
132+
133+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
134+
135+
## Troubleshoot Terraform on Azure
136+
137+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
138+
139+
## Next steps
140+
141+
> [!div class="nextstepaction"]
142+
> [View and configure DDoS protection telemetry](telemetry.md)

0 commit comments

Comments
 (0)