Skip to content

Commit 2cdb244

Browse files
authored
Merge pull request #294816 from TomArcherMsft/101-virtual-network-public-ip
101-virtual-network-public-ip
2 parents 2a559b3 + c481817 commit 2cdb244

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
title: 'Quickstart: Create a public IP - Terraform'
3+
titleSuffix: Azure Virtual Network
4+
description: Learn how to create a public IP address using Terraform
5+
services: virtual-network
6+
author: mbender-ms
7+
ms.author: mbender
8+
ms.service: azure-virtual-network
9+
ms.topic: quickstart
10+
ms.date: 01/09/2025
11+
ms.custom: mode-api, devx-track-terraform
12+
---
13+
14+
# Quickstart: Create a public IP address using Terraform
15+
16+
In this quickstart, you learn how to create an Azure public IP address. Public IP addresses in Azure are used for public connections to Azure resources. Public IP addresses are available in two SKUs: basic, and standard. Two tiers of public IP addresses are available: regional, and global. The routing preference of a public IP address is set when created. Internet routing and Microsoft Network routing are the available choices.
17+
18+
:::image type="content" source="./media/create-public-ip-portal/public-ip-example-resources.png" alt-text="Diagram of an example use of a public IP address. A public IP address is assigned to a load balancer.":::
19+
20+
[!INCLUDE [quickstarts-free-trial-note](~/reusable-content/ce-skilling/azure/includes/quickstarts-free-trial-note.md)]
21+
22+
[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
23+
24+
In this article, you learn how to:
25+
26+
> [!div class="checklist"]
27+
> * 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)
28+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
29+
> * Create a standard zone-redundant public IPv4 address named **myStandardPublicIP**
30+
> * Create a basic static public IPv4 address named **myBasicPublicIP**
31+
> * Create a standard zonal public IPv4 address in Zone 2 named **myZonalStandardPublicIP**
32+
> * Create a non-zonal IP address named **myNonZonalStandardPublicIP**
33+
> * Create a standard static public IPv4 address named **myRoutingPreferenceStandardPublicIP** that supports the Routing Preference feature
34+
> * Create a standard static public IPv4 address named **myGlobalTierStandardPublicIP** that supports the Global Tier feature
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-virtual-network-public-ip). 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/TestRecord.md).
38+
>
39+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform).
40+
41+
## Create a resource group
42+
43+
An Azure resource group is a logical container into which Azure resources are deployed and managed.
44+
45+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="1-8":::
46+
47+
## Create public IP
48+
49+
# [**Standard SKU**](#tab/create-public-ip-standard)
50+
51+
>[!NOTE]
52+
>Standard SKU public IP is recommended for production workloads. For more information about SKUs, see **[Public IP addresses](public-ip-addresses.md)**.
53+
>
54+
>The following command snippet 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).
55+
56+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="10-18":::
57+
58+
> [!IMPORTANT]
59+
> For versions of the API older than 2020-08-01, omit the `zone` field to create a zone-redundant IP address.
60+
>
61+
62+
# [**Basic SKU**](#tab/create-public-ip-basic)
63+
64+
In this section, you create a basic IP. Basic public IPs don't support availability zones.
65+
66+
The following code snippet creates an IPv6 address. For an IPv6 address, set the `version` value to **IPv6**.
67+
68+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="20-27":::
69+
70+
If it's acceptable for the IP address to change over time, dynamic IP assignment can be selected by changing the `allocation_method` value to **Dynamic**.
71+
72+
>[!NOTE]
73+
> A basic IPv6 address must always be dynamic.
74+
75+
---
76+
77+
## Create a zonal or no-zone IP address
78+
79+
In this section, you learn how to create a zonal and a non-zone public IP address.
80+
81+
# [**Zonal**](#tab/create-public-ip-zonal)
82+
83+
The following code snippet creates a standard zonal public IPv4 address in Zone 2 named **myZonalStandardPublicIP**.
84+
85+
To create an IPv6 address, set the `version` value to **IPv6**.
86+
87+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="29-37":::
88+
89+
>[!NOTE]
90+
>For more information about availability zones, see [What are availability zones?](../../reliability/availability-zones-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json).
91+
92+
# [**Non-zonal**](#tab/create-public-ip-non-zonal)
93+
94+
The following code snippet creates a standard public IPv4 address as a non-zonal resource named **myNonZonalStandardPublicIP**.
95+
96+
>[!NOTE]
97+
>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).
98+
99+
To create an IPv6 address, set the `version` value to **IPv6**.
100+
101+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="39-46":::
102+
103+
The removal of the `zone` field is valid in all regions.
104+
105+
The removal 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).
106+
107+
---
108+
109+
## Routing Preference and Tier
110+
111+
Standard SKU static public IPv4 addresses support Routing Preference or the Global Tier feature.
112+
113+
# [**Routing Preference**](#tab/routing-preference)
114+
115+
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.
116+
117+
The selection of **Internet** minimizes travel on Microsoft's network, instead using the transit ISP network to deliver traffic at a cost-optimized rate.
118+
119+
For more information on routing preference, see [What is routing preference (preview)?](routing-preference-overview.md).
120+
121+
The following code snippet creates a new standard zone-redundant public IPv4 address with a routing preference of type **Internet**:
122+
123+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="48-61":::
124+
125+
# [**Tier**](#tab/tier)
126+
127+
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.
128+
129+
For more information, see [Cross-region load balancer](../../load-balancer/cross-region-overview.md).
130+
131+
The following code snippet creates a global IPv4 address. This address can be associated with the frontend of a cross-region load balancer.
132+
133+
:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="63-71":::
134+
135+
>[!NOTE]
136+
>Global tier addresses don't support Availability Zones.
137+
138+
---
139+
140+
## Clean up resources
141+
142+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
143+
144+
## Troubleshoot Terraform on Azure
145+
146+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
147+
148+
## Next steps
149+
150+
> [!div class="nextstepaction"]
151+
> [Create public IP prefix using the Azure CLI](create-public-ip-prefix-cli.md)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ items:
1313
href: create-public-ip-powershell.md
1414
- name: Create public IP address - Azure CLI
1515
href: create-public-ip-cli.md
16+
- name: Create public IP address - Terraform
17+
href: create-public-ip-terraform.md
1618
- name: Create public IP address - ARM template
1719
href: create-public-ip-template.md
1820
- name: Create public IP prefix - Portal

0 commit comments

Comments
 (0)