Skip to content

Commit ad88ab3

Browse files
committed
New Terraform article for public ip prefix section
1 parent cabdcef commit ad88ab3

File tree

3 files changed

+201
-10
lines changed

3 files changed

+201
-10
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
---
2+
title: 'Quickstart: Create a public IP address prefix - Terraform'
3+
titleSuffix: Azure Virtual Network
4+
description: Learn how to create a public IP address prefix using Terraform.
5+
services: virtual-network
6+
author: mbender-ms
7+
ms.author: mbender
8+
ms.service: azure-virtual-network
9+
ms.subservice: ip-services
10+
ms.topic: quickstart
11+
ms.date: 02/18/2025
12+
ms.custom: mode-api, devx-track-terraform
13+
---
14+
15+
# Quickstart: Create a public IP address prefix using Terraform
16+
17+
Learn about a public IP address prefix and how to create, change, and delete one. A public IP address prefix is a contiguous range of standard SKU public IP addresses.
18+
19+
When you create a public IP address resource, you can assign a static public IP address from the prefix and associate the address to virtual machines, load balancers, or other resources. For more information, see [Public IP address prefix overview](public-ip-address-prefix.md).
20+
21+
[!INCLUDE [quickstarts-free-trial-note](~/reusable-content/ce-skilling/azure/includes/quickstarts-free-trial-note.md)]
22+
23+
[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
24+
25+
- This tutorial requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
26+
27+
In this article, you learn how to:
28+
29+
> [!div class="checklist"]
30+
> * 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)
31+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
32+
> * Create a standard zone-redundant public IPv4 address prefix named **myIPv4**
33+
> * Create a standard zonal public IPv4 address named **myIPv4Zonal**
34+
> * Create a standard non-zonal public IPv4 address named **myIPv4NonZonal**
35+
> * Create a standard public IPv4 address named **myIPv4RPInternet** that supports the Routing Preference feature
36+
> * Create a standard zone-redundant public IPv6 address prefix named **myIPv6**
37+
> * Create a standard zonal public IPv6 address named **myIPv6Zonal**
38+
> * Create a standard non-zonal public IPv6 address named **myIPv6NonZonal**
39+
> * Create a static public IP IPv4 address from an IP prefix
40+
> * Create a static public IP IPv6 address from a IP prefix
41+
42+
> [!NOTE]
43+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-virtual-network-public-ip-prefix). 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-virtual-network-public-ip-prefix/TestRecord.md).
44+
>
45+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform).
46+
47+
## Create a resource group
48+
49+
An Azure resource group is a logical container into which Azure resources are deployed and managed.
50+
51+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="1-10":::
52+
53+
## Create a public IP address prefix
54+
55+
In this section, you create a zone redundant, a zonal, and a non-zonal public IP prefix using Azure PowerShell.
56+
57+
The prefixes in the examples are:
58+
59+
* **IPv4** - /28 (16 addresses)
60+
61+
* **IPv6** - /124 (16 addresses)
62+
63+
For more information on available prefix sizes, see [Prefix sizes](public-ip-address-prefix.md#prefix-sizes).
64+
65+
## IPv4
66+
67+
# [Zone redundant IPv4 prefix](#tab/ipv4-zone-redundant)
68+
69+
To create an IPv4 public IP prefix, specify **IPv4** as the `ip_version` value. To create a zone redundant IPv4 prefix, specify **["1", "2", "3"]** as the `zone` value.
70+
71+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="12-22" highlight="18-19,21":::
72+
73+
# [Zonal IPv4 prefix](#tab/ipv4-zonal)
74+
75+
To create an IPv4 public IP prefix, specify **IPv4** as the `ip_version` value. To create a zonal IP prefix in zone 2, specify **["2"]** as the `zone` value.
76+
77+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="24-34":::
78+
79+
>[!NOTE]
80+
>For more information about availability zones, see [What are availability zones?](../../reliability/availability-zones-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json).
81+
82+
# [Non-zonal IPv4 prefix](#tab/ipv4-non-zonal)
83+
84+
To create an IPv4 public IP prefix, specify **IPv4** as the `ip_version` value. To create a non-zonal IP prefix, omit the `zone` field.
85+
86+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="36-44":::
87+
88+
The omission of the `zone` field is valid in all regions.
89+
90+
The omission of the `zone` field is the default selection for standard public IP addresses in regions without [Availability Zones](../../reliability/availability-zones-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json).
91+
92+
---
93+
94+
# [Routing Preference Internet IPv4 prefix](#tab/ipv4-routing-pref)
95+
96+
To create an IPv4 public IP prefix with routing preference set to Internet, add **RoutingPreference=Internet** to the `tags` block.
97+
98+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="46-58":::
99+
100+
---
101+
102+
## IPv6
103+
104+
# [Zone redundant IPv6 prefix](#tab/ipv6-zone-redundant)
105+
106+
To create an IPv6 public IP prefix, specify **IPv6** as the `ip_version` value. To create a zone redundant IPv6 prefix, specify **["1", "2", "3"]** as the `zone` value.
107+
108+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="60-70":::
109+
110+
# [Zonal IPv6 prefix](#tab/ipv6-zonal)
111+
112+
To create an IPv6 public IP prefix, specify **IPv6** as the `ip_version` value. To create a zone redundant IPv6 prefix, specify **["2"]** as the `zone` value.
113+
114+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="72-82":::
115+
116+
>[!NOTE]
117+
>For more information about availability zones, see [What are availability zones?](../../reliability/availability-zones-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json).
118+
119+
# [Non-zonal IPv6 prefix](#tab/ipv6-non-zonal)
120+
121+
To create an IPv6 public IP prefix, specify **IPv6** as the `ip_version` value. To create a non-zonal IP prefix, omit the `zone` field.
122+
123+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="84-92":::
124+
125+
The omission of the `zone` field is valid in all regions.
126+
127+
The omission of the `zone` field is the default selection for standard public IP addresses in regions without [Availability Zones](../../reliability/availability-zones-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json).
128+
129+
---
130+
131+
## Create a static public IP address from a prefix
132+
133+
Once you create a prefix, you must create static IP addresses from the prefix. In this section, you see how to create a prefix and then create an address that points to the prefix.
134+
135+
# [IPv4 address](#tab/ipv4-address)
136+
137+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="107-115,93-105":::
138+
139+
# [IPv6 address](#tab/ipv6-address)
140+
141+
To create a IPv6 public IP prefix, enter **IPv6** in the `--version` parameter.
142+
143+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="130-138, 116-128":::
144+
145+
---
146+
147+
>[!NOTE]
148+
>Only static public IP addresses created with the standard SKU can be assigned from the prefix's range. To learn more about public IP address SKUs, see [public IP address](public-ip-addresses.md#public-ip-addresses).
149+
150+
## Delete a prefix
151+
152+
In this section, you learn how to delete a prefix at the command line.
153+
154+
# [Azure CLI](#tab/azure-cli)
155+
156+
To delete a public IP prefix, use [az network public-ip prefix delete](/cli/azure/network/public-ip/prefix#az-network-public-ip-prefix-delete).
157+
158+
```azurecli
159+
az network public-ip prefix delete \
160+
--resource-group <resource_group_name>
161+
--name <public_ip_prefix_name> \
162+
```
163+
164+
# [Azure PowerShell](#tab/azure-powershell)
165+
166+
To delete a public IP prefix, use [Remove-AzPublicIpPrefix](/powershell/module/az.network/remove-azpublicipprefix).
167+
168+
```azurepowershell
169+
Remove-AzPublicIpPrefix ResourceGroupName=<resource_group_name> `
170+
Name=<public_ip_prefix_name>
171+
```
172+
173+
>[!NOTE]
174+
>If addresses within the prefix are associated with public IP address resources, delete the public IP address resources first. For more information about deleting a public IP address, see [delete a public IP address](virtual-network-public-ip-address.md#view-modify-settings-for-or-delete-a-public-ip-address).
175+
176+
---
177+
178+
## Clean up resources
179+
180+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
181+
182+
## Troubleshoot Terraform on Azure
183+
184+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
185+
186+
## Next steps
187+
188+
> [!div class="nextstepaction"]
189+
> [Create a public IP using Terraform](create-public-ip-terraform.md)

articles/virtual-network/ip-services/create-public-ip-terraform.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: mbender-ms
77
ms.author: mbender
88
ms.service: azure-virtual-network
99
ms.topic: quickstart
10-
ms.date: 01/09/2025
10+
ms.date: 01/18/2025
1111
ms.custom: mode-api, devx-track-terraform
1212
---
1313

@@ -46,7 +46,7 @@ An Azure resource group is a logical container into which Azure resources are de
4646

4747
## Create public IP
4848

49-
# [**Standard SKU**](#tab/create-public-ip-standard)
49+
# [Standard SKU](#tab/create-public-ip-standard)
5050

5151
>[!NOTE]
5252
>Standard SKU public IP is recommended for production workloads. For more information about SKUs, see **[Public IP addresses](public-ip-addresses.md)**.
@@ -59,11 +59,11 @@ An Azure resource group is a logical container into which Azure resources are de
5959
> For versions of the API older than 2020-08-01, omit the `zone` field to create a zone-redundant IP address.
6060
>
6161
62-
# [**Basic SKU**](#tab/create-public-ip-basic)
62+
# [Basic SKU](#tab/create-public-ip-basic)
6363

6464
In this section, you create a basic IP. Basic public IPs don't support availability zones.
6565

66-
The following code snippet creates an IPv6 address. For an IPv6 address, set the `version` value to **IPv6**.
66+
The following code snippet creates an IPv6 address. For an IPv6 address, set the `ip_version` value to **IPv6**.
6767

6868
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="20-27":::
6969

@@ -78,25 +78,25 @@ If it's acceptable for the IP address to change over time, dynamic IP assignment
7878

7979
In this section, you learn how to create a zonal and a non-zone public IP address.
8080

81-
# [**Zonal**](#tab/create-public-ip-zonal)
81+
# [Zonal](#tab/create-public-ip-zonal)
8282

8383
The following code snippet creates a standard zonal public IPv4 address in Zone 2 named **myZonalStandardPublicIP**.
8484

85-
To create an IPv6 address, set the `version` value to **IPv6**.
85+
To create an IPv6 address, set the `ip_version` value to **IPv6**.
8686

8787
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="29-37":::
8888

8989
>[!NOTE]
9090
>For more information about availability zones, see [What are availability zones?](../../reliability/availability-zones-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json).
9191
92-
# [**Non-zonal**](#tab/create-public-ip-non-zonal)
92+
# [Non-zonal](#tab/create-public-ip-non-zonal)
9393

9494
The following code snippet creates a standard public IPv4 address as a non-zonal resource named **myNonZonalStandardPublicIP**.
9595

9696
>[!NOTE]
9797
>The following command works for API version 2020-08-01 or later. For more information about the API version currently being used, see [Resource Providers and Types](../../azure-resource-manager/management/resource-providers-and-types.md).
9898
99-
To create an IPv6 address, set the `version` value to **IPv6**.
99+
To create an IPv6 address, set the `ip_version` value to **IPv6**.
100100

101101
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="39-46":::
102102

@@ -110,7 +110,7 @@ The removal of the `zone` field is the default selection for standard public IP
110110

111111
Standard SKU static public IPv4 addresses support Routing Preference or the Global Tier feature.
112112

113-
# [**Routing Preference**](#tab/routing-preference)
113+
# [Routing Preference](#tab/routing-preference)
114114

115115
By default, the routing preference for public IP addresses is set to **Microsoft network**, which delivers traffic over Microsoft's global wide area network to the user.
116116

@@ -122,7 +122,7 @@ The following code snippet creates a new standard zone-redundant public IPv4 add
122122

123123
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="48-61":::
124124

125-
# [**Tier**](#tab/tier)
125+
# [Tier](#tab/tier)
126126

127127
Public IP addresses are associated with a single region. The **Global** tier spans an IP address across multiple regions. **Global** tier is required for the frontends of cross-region load balancers.
128128

articles/virtual-network/ip-services/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ items:
2323
href: create-public-ip-prefix-powershell.md
2424
- name: Create public IP prefix - Azure CLI
2525
href: create-public-ip-prefix-cli.md
26+
- name: Create public IP prefix - Terraform
27+
href: create-public-ip-prefix-terraform.md
2628
expanded: true
2729
- name: Tutorials
2830
items:

0 commit comments

Comments
 (0)