Skip to content

Commit 904b1bd

Browse files
authored
Merge pull request #294880 from TomArcherMsft/101-virtual-network-public-ip-prefix
101-virtual-network-public-ip-prefix
2 parents 862afaf + 60d1923 commit 904b1bd

File tree

3 files changed

+197
-10
lines changed

3 files changed

+197
-10
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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+
In this article, you learn how to:
26+
27+
> [!div class="checklist"]
28+
> * 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)
29+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
30+
> * Create a standard zone-redundant public IPv4 address prefix named **myIPv4**
31+
> * Create a standard zonal public IPv4 address named **myIPv4Zonal**
32+
> * Create a standard non-zonal public IPv4 address named **myIPv4NonZonal**
33+
> * Create a standard public IPv4 address named **myIPv4RPInternet** that supports the Routing Preference feature
34+
> * Create a standard zone-redundant public IPv6 address prefix named **myIPv6**
35+
> * Create a standard zonal public IPv6 address named **myIPv6Zonal**
36+
> * Create a standard non-zonal public IPv6 address named **myIPv6NonZonal**
37+
> * Create a static public IP IPv4 address from an IP prefix
38+
> * Create a static public IP IPv6 address from an IP prefix
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-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).
42+
>
43+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform).
44+
45+
## Create a resource group
46+
47+
An Azure resource group is a logical container into which Azure resources are deployed and managed.
48+
49+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="1-10":::
50+
51+
## Create a public IP address prefix
52+
53+
In this section, you create a zone redundant, a zonal, and a non-zonal public IP prefix using Azure PowerShell.
54+
55+
The prefixes in the examples are:
56+
57+
* **IPv4** - /28 (16 addresses)
58+
59+
* **IPv6** - /124 (16 addresses)
60+
61+
For more information on available prefix sizes, see [Prefix sizes](public-ip-address-prefix.md#prefix-sizes).
62+
63+
## IPv4
64+
65+
# [Zone redundant IPv4 prefix](#tab/ipv4-zone-redundant)
66+
67+
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.
68+
69+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="12-22" highlight="7-8,10":::
70+
71+
# [Zonal IPv4 prefix](#tab/ipv4-zonal)
72+
73+
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.
74+
75+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="24-34" highlight="7-8,10":::
76+
77+
>[!NOTE]
78+
>For more information about availability zones, see [What are availability zones?](../../reliability/availability-zones-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json).
79+
80+
# [Non-zonal IPv4 prefix](#tab/ipv4-non-zonal)
81+
82+
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.
83+
84+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="36-44" highlight="7-8":::
85+
86+
The omission of the `zone` field is valid in all regions.
87+
88+
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).
89+
90+
---
91+
92+
# [Routing Preference Internet IPv4 prefix](#tab/ipv4-routing-pref)
93+
94+
To create an IPv4 public IP prefix with routing preference set to Internet, add **RoutingPreference=Internet** to the `tags` block.
95+
96+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="46-58" highlight="7-8,10-12":::
97+
98+
---
99+
100+
## IPv6
101+
102+
# [Zone redundant IPv6 prefix](#tab/ipv6-zone-redundant)
103+
104+
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.
105+
106+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="60-70" highlight="7-8,10":::
107+
108+
# [Zonal IPv6 prefix](#tab/ipv6-zonal)
109+
110+
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.
111+
112+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="72-82" highlight="7-8,10":::
113+
114+
>[!NOTE]
115+
>For more information about availability zones, see [What are availability zones?](../../reliability/availability-zones-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json).
116+
117+
# [Non-zonal IPv6 prefix](#tab/ipv6-non-zonal)
118+
119+
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.
120+
121+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="84-92" highlight="7-8":::
122+
123+
The omission of the `zone` field is valid in all regions.
124+
125+
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).
126+
127+
---
128+
129+
## Create a static public IP address from a prefix
130+
131+
Once you create a prefix, you can 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.
132+
133+
# [IPv4 address](#tab/ipv4-address)
134+
135+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="107-115,93-105" highlight="2,21":::
136+
137+
# [IPv6 address](#tab/ipv6-address)
138+
139+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip-prefix/main.tf" range="130-138, 116-128" highlight="2,21":::
140+
141+
---
142+
143+
>[!NOTE]
144+
>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).
145+
146+
## Delete a prefix
147+
148+
In this section, you learn how to delete a prefix at the command line.
149+
150+
# [Azure CLI](#tab/azure-cli)
151+
152+
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).
153+
154+
```azurecli
155+
az network public-ip prefix delete \
156+
--resource-group <resource_group_name>
157+
--name <public_ip_prefix_name> \
158+
```
159+
160+
# [Azure PowerShell](#tab/azure-powershell)
161+
162+
To delete a public IP prefix, use [Remove-AzPublicIpPrefix](/powershell/module/az.network/remove-azpublicipprefix).
163+
164+
```azurepowershell
165+
Remove-AzPublicIpPrefix -ResourceGroupName <resource_group_name> `
166+
-Name <public_ip_prefix_name>
167+
```
168+
169+
>[!NOTE]
170+
>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).
171+
172+
---
173+
174+
## Clean up resources
175+
176+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
177+
178+
## Troubleshoot Terraform on Azure
179+
180+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
181+
182+
## Next steps
183+
184+
> [!div class="nextstepaction"]
185+
> [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)