|
| 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 | +## Create a resource group |
| 37 | + |
| 38 | +An Azure resource group is a logical container into which Azure resources are deployed and managed. |
| 39 | + |
| 40 | +:::code language="terraform" source="~/terraform_samples/quickstart/101-virtual-network-public-ip/main.tf" range="1-8"::: |
| 41 | + |
| 42 | +## Create public IP |
| 43 | + |
| 44 | +# [**Standard SKU**](#tab/create-public-ip-standard) |
| 45 | + |
| 46 | +>[!NOTE] |
| 47 | +>Standard SKU public IP is recommended for production workloads. For more information about SKUs, see **[Public IP addresses](public-ip-addresses.md)**. |
| 48 | +> |
| 49 | +>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). |
| 50 | +
|
| 51 | +Use [az network public-ip create](/cli/azure/network/public-ip#az-network-public-ip-create) to create a standard zone-redundant public IPv4 address named **myStandardPublicIP** in **QuickStartCreateIP-rg**. |
| 52 | + |
| 53 | +To create an IPv6 address, modify the `--version` parameter to **IPv6**. |
| 54 | + |
| 55 | +```azurecli-interactive |
| 56 | + az network public-ip create \ |
| 57 | + --resource-group QuickStartCreateIP-rg \ |
| 58 | + --name myStandardPublicIP \ |
| 59 | + --version IPv4 \ |
| 60 | + --sku Standard \ |
| 61 | + --zone 1 2 3 |
| 62 | +``` |
| 63 | +> [!IMPORTANT] |
| 64 | +> For versions of the API older than 2020-08-01, execute the command without specifying a `--zone` parameter to create a zone-redundant IP address. |
| 65 | +> |
| 66 | +
|
| 67 | +# [**Basic SKU**](#tab/create-public-ip-basic) |
| 68 | + |
| 69 | +In this section, you create a basic IP. Basic public IPs don't support availability zones. |
| 70 | + |
| 71 | +Use [az network public-ip create](/cli/azure/network/public-ip#az-network-public-ip-create) to create a basic static public IPv4 address named **myBasicPublicIP** in **QuickStartCreateIP-rg**. |
| 72 | + |
| 73 | +To create an IPv6 address, modify the `--version` parameter to **IPv6**. |
| 74 | + |
| 75 | +```azurecli-interactive |
| 76 | + az network public-ip create \ |
| 77 | + --resource-group QuickStartCreateIP-rg \ |
| 78 | + --name myBasicPublicIP \ |
| 79 | + --version IPv4 \ |
| 80 | + --sku Basic \ |
| 81 | + --allocation-method Static |
| 82 | +``` |
| 83 | +If it's acceptable for the IP address to change over time, **Dynamic** IP assignment can be selected by changing the **`--allocation-method`** to **Dynamic**. |
| 84 | + |
| 85 | +>[!NOTE] |
| 86 | +> A basic IPv6 address must always be `Dynamic`. |
| 87 | +
|
| 88 | +--- |
| 89 | + |
| 90 | +## Create a zonal or no-zone IP address |
| 91 | + |
| 92 | +In this section, you learn how to create a zonal or no-zone public IP address. |
| 93 | + |
| 94 | +# [**Zonal**](#tab/create-public-ip-zonal) |
| 95 | + |
| 96 | +To create a standard zonal public IPv4 address in Zone 2 named **myStandardPublicIP** in **QuickStartCreateIP-rg**, use the following command. |
| 97 | + |
| 98 | +To create an IPv6 address, modify the `--version` parameter to **IPv6**. |
| 99 | + |
| 100 | +```azurecli-interactive |
| 101 | + az network public-ip create \ |
| 102 | + --resource-group QuickStartCreateIP-rg \ |
| 103 | + --name myStandardPublicIP-zonal \ |
| 104 | + --version IPv4 \ |
| 105 | + --sku Standard \ |
| 106 | + --zone 2 |
| 107 | +``` |
| 108 | + |
| 109 | +>[!NOTE] |
| 110 | +>The above options for zones are only valid selections in regions with [Availability Zones](../../reliability/availability-zones-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json). |
| 111 | +
|
| 112 | +# [**Non-zonal**](#tab/create-public-ip-non-zonal) |
| 113 | + |
| 114 | +In this section, you create a non-zonal IP address. |
| 115 | + |
| 116 | +>[!NOTE] |
| 117 | +>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). |
| 118 | +
|
| 119 | +Use [az network public-ip create](/cli/azure/network/public-ip#az-network-public-ip-create) to create a standard public IPv4 address as a non-zonal resource named **myStandardPublicIP-nozone** in **QuickStartCreateIP-rg**. |
| 120 | + |
| 121 | +To create an IPv6 address, modify the `--version` parameter to **IPv6**. |
| 122 | + |
| 123 | +```azurecli-interactive |
| 124 | + az network public-ip create \ |
| 125 | + --resource-group QuickStartCreateIP-rg \ |
| 126 | + --name myStandardPublicIP-nozone \ |
| 127 | + --version IPv4 \ |
| 128 | + --sku Standard |
| 129 | +``` |
| 130 | +The removal of the `--zone` parameter in the command is valid in all regions. |
| 131 | + |
| 132 | +The removal of the `--zone` parameter 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). |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## Routing Preference and Tier |
| 137 | + |
| 138 | +Standard SKU static public IPv4 addresses support Routing Preference or the Global Tier feature. |
| 139 | + |
| 140 | +# [**Routing Preference**](#tab/routing-preference) |
| 141 | + |
| 142 | +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. |
| 143 | + |
| 144 | +The selection of **Internet** minimizes travel on Microsoft's network, instead using the transit ISP network to deliver traffic at a cost-optimized rate. |
| 145 | + |
| 146 | +For more information on routing preference, see [What is routing preference (preview)?](routing-preference-overview.md). |
| 147 | + |
| 148 | +The command creates a new standard zone-redundant public IPv4 address with a routing preference of type **Internet**: |
| 149 | + |
| 150 | +```azurecli-interactive |
| 151 | + az network public-ip create \ |
| 152 | + --resource-group QuickStartCreateIP-rg \ |
| 153 | + --name myStandardPublicIP-RP \ |
| 154 | + --version IPv4 \ |
| 155 | + --ip-tags 'RoutingPreference=Internet' \ |
| 156 | + --sku Standard \ |
| 157 | + --zone 1 2 3 |
| 158 | +``` |
| 159 | + |
| 160 | +# [**Tier**](#tab/tier) |
| 161 | + |
| 162 | +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. |
| 163 | + |
| 164 | +For more information, see [Cross-region load balancer](../../load-balancer/cross-region-overview.md). |
| 165 | + |
| 166 | +The following command creates a global IPv4 address. This address can be associated with the frontend of a cross-region load balancer. |
| 167 | + |
| 168 | +```azurecli-interactive |
| 169 | + az network public-ip create \ |
| 170 | + --resource-group QuickStartCreateIP-rg \ |
| 171 | + --name myStandardPublicIP-Global \ |
| 172 | + --version IPv4 \ |
| 173 | + --tier global \ |
| 174 | + --sku Standard |
| 175 | +``` |
| 176 | +>[!NOTE] |
| 177 | +>Global tier addresses don't support Availability Zones. |
| 178 | +
|
| 179 | +--- |
| 180 | + |
| 181 | +## Clean up resources |
| 182 | + |
| 183 | +If you're not going to continue to use this application, delete the public IP address with the following steps: |
| 184 | + |
| 185 | +1. In the search box at the top of the portal, enter **Resource group**. |
| 186 | + |
| 187 | +2. In the search results, select **Resource groups**. |
| 188 | + |
| 189 | +3. Select **QuickStartCreateIP-rg**. |
| 190 | + |
| 191 | +4. Select **Delete resource group**. |
| 192 | + |
| 193 | +5. Enter **QuickStartCreateIP-rg** for **TYPE THE RESOURCE GROUP NAME** and select **Delete**. |
| 194 | + |
| 195 | +## Next steps |
| 196 | + |
| 197 | +Advance to the next article to learn how to create a public IP prefix: |
| 198 | +> [!div class="nextstepaction"] |
| 199 | +> [Create public IP prefix using the Azure CLI](create-public-ip-prefix-cli.md) |
0 commit comments