|
| 1 | +--- |
| 2 | +title: "Public IP Prefix" |
| 3 | +description: Get started with Azure Public IP Prefix on LocalStack |
| 4 | +template: doc |
| 5 | +--- |
| 6 | + |
| 7 | +import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage"; |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +Azure Public IP Prefix is a contiguous range of Standard SKU static public IP addresses. |
| 12 | +When you create a public IP address from a prefix, the address is guaranteed to stay within the prefix range, making it useful for allow-listing IP ranges in external firewalls. |
| 13 | +Public IP Prefixes are commonly used with NAT Gateway to provide predictable outbound IP addresses for entire subnets. For more information, see [Public IP address prefixes](https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/public-ip-address-prefix). |
| 14 | + |
| 15 | +LocalStack for Azure provides a local environment for building and testing applications that make use of Public IP Prefixes. |
| 16 | +The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Public IP Prefix's integration with LocalStack. |
| 17 | + |
| 18 | +## Getting started |
| 19 | + |
| 20 | +This guide is designed for users new to Public IP Prefixes and assumes basic knowledge of the Azure CLI and our `azlocal` wrapper script. |
| 21 | + |
| 22 | +Launch LocalStack using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/). Once the container is running, enable Azure CLI interception by running: |
| 23 | + |
| 24 | +```bash |
| 25 | +azlocal start-interception |
| 26 | +``` |
| 27 | + |
| 28 | +This command points the `az` CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API. |
| 29 | +To revert this configuration, run: |
| 30 | + |
| 31 | +```bash |
| 32 | +azlocal stop-interception |
| 33 | +``` |
| 34 | + |
| 35 | +This reconfigures the `az` CLI to send commands to the official Azure management REST API. |
| 36 | + |
| 37 | +### Create a resource group |
| 38 | + |
| 39 | +Create a resource group to hold all resources created in this guide: |
| 40 | + |
| 41 | +```bash |
| 42 | +az group create \ |
| 43 | + --name rg-pip-prefix-demo \ |
| 44 | + --location westeurope |
| 45 | +``` |
| 46 | + |
| 47 | +```bash title="Output" |
| 48 | +{ |
| 49 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-pip-prefix-demo", |
| 50 | + "location": "westeurope", |
| 51 | + "managedBy": null, |
| 52 | + "name": "rg-pip-prefix-demo", |
| 53 | + "properties": { |
| 54 | + "provisioningState": "Succeeded" |
| 55 | + }, |
| 56 | + "tags": null, |
| 57 | + "type": "Microsoft.Resources/resourceGroups" |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +### Create a public IP prefix |
| 62 | + |
| 63 | +Create a /29 public IP prefix (8 IP addresses): |
| 64 | + |
| 65 | +```bash |
| 66 | +az network public-ip prefix create \ |
| 67 | + --name pip-prefix-demo \ |
| 68 | + --resource-group rg-pip-prefix-demo \ |
| 69 | + --location westeurope \ |
| 70 | + --length 29 |
| 71 | +``` |
| 72 | + |
| 73 | +```bash title="Output" |
| 74 | +{ |
| 75 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-pip-prefix-demo/providers/Microsoft.Network/publicIPPrefixes/pip-prefix-demo", |
| 76 | + "location": "westeurope", |
| 77 | + "name": "pip-prefix-demo", |
| 78 | + "properties": { |
| 79 | + "ipPrefix": "20.184.13.0/29", |
| 80 | + "ipTags": [], |
| 81 | + "prefixLength": 29, |
| 82 | + "provisioningState": "Succeeded", |
| 83 | + "publicIPAddressVersion": "IPv4", |
| 84 | + "resourceGuid": "00000000-0000-0000-0000-000000000000" |
| 85 | + ... |
| 86 | + }, |
| 87 | + "resourceGroup": "rg-pip-prefix-demo", |
| 88 | + "sku": { |
| 89 | + "name": "Standard", |
| 90 | + "tier": "Regional" |
| 91 | + }, |
| 92 | + "type": "Microsoft.Network/publicIPPrefixes", |
| 93 | + "zones": [] |
| 94 | + ... |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +### Get and list public IP prefixes |
| 99 | + |
| 100 | +Retrieve the details of the public IP prefix and list all prefixes in the resource group: |
| 101 | + |
| 102 | +```bash |
| 103 | +az network public-ip prefix show \ |
| 104 | + --name pip-prefix-demo \ |
| 105 | + --resource-group rg-pip-prefix-demo |
| 106 | +``` |
| 107 | + |
| 108 | +```bash title="Output" |
| 109 | +{ |
| 110 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-pip-prefix-demo/providers/Microsoft.Network/publicIPPrefixes/pip-prefix-demo", |
| 111 | + "location": "westeurope", |
| 112 | + "name": "pip-prefix-demo", |
| 113 | + "properties": { |
| 114 | + "ipPrefix": "20.184.13.0/29", |
| 115 | + "ipTags": [], |
| 116 | + "prefixLength": 29, |
| 117 | + "provisioningState": "Succeeded", |
| 118 | + "publicIPAddressVersion": "IPv4", |
| 119 | + "resourceGuid": "00000000-0000-0000-0000-000000000000" |
| 120 | + ... |
| 121 | + }, |
| 122 | + "resourceGroup": "rg-pip-prefix-demo", |
| 123 | + "sku": { |
| 124 | + "name": "Standard", |
| 125 | + "tier": "Regional" |
| 126 | + }, |
| 127 | + "type": "Microsoft.Network/publicIPPrefixes", |
| 128 | + "zones": [] |
| 129 | + ... |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +Then list all public IP prefixes in the resource group: |
| 134 | + |
| 135 | +```bash |
| 136 | +az network public-ip prefix list \ |
| 137 | + --resource-group rg-pip-prefix-demo |
| 138 | +``` |
| 139 | + |
| 140 | +```bash title="Output" |
| 141 | +[ |
| 142 | + { |
| 143 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-pip-prefix-demo/providers/Microsoft.Network/publicIPPrefixes/pip-prefix-demo", |
| 144 | + "location": "westeurope", |
| 145 | + "name": "pip-prefix-demo", |
| 146 | + "properties": { |
| 147 | + "ipPrefix": "20.184.13.0/29", |
| 148 | + "ipTags": [], |
| 149 | + "prefixLength": 29, |
| 150 | + "provisioningState": "Succeeded", |
| 151 | + "publicIPAddressVersion": "IPv4" |
| 152 | + }, |
| 153 | + "resourceGroup": "rg-pip-prefix-demo", |
| 154 | + "sku": { "name": "Standard", "tier": "Regional" }, |
| 155 | + "type": "Microsoft.Network/publicIPPrefixes", |
| 156 | + "zones": [] |
| 157 | + } |
| 158 | +] |
| 159 | +``` |
| 160 | +
|
| 161 | +### Delete the public IP prefix |
| 162 | +
|
| 163 | +Delete the public IP prefix and verify it no longer appears in the list: |
| 164 | +
|
| 165 | +```bash |
| 166 | +az network public-ip prefix delete \ |
| 167 | + --name pip-prefix-demo \ |
| 168 | + --resource-group rg-pip-prefix-demo |
| 169 | +``` |
| 170 | +
|
| 171 | +Then list all public IP prefixes to confirm the resource group is now empty: |
| 172 | +
|
| 173 | +```bash |
| 174 | +az network public-ip prefix list --resource-group rg-pip-prefix-demo |
| 175 | +``` |
| 176 | +
|
| 177 | +```bash title="Output" |
| 178 | +[] |
| 179 | +``` |
| 180 | +
|
| 181 | +## Features |
| 182 | +
|
| 183 | +The Public IP Prefix emulator supports the following features: |
| 184 | +
|
| 185 | +- **Create and manage prefixes**: Full lifecycle management including create, get, update, list, and delete. |
| 186 | +- **Configurable prefix length**: For IPv4, set prefix length /28 through /31 to define how many addresses the range contains (/28 = 16, /29 = 8, /30 = 4, /31 = 2 addresses), matching Azure’s [published prefix sizes](https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/public-ip-address-prefix#prefix-sizes). IPv6 uses /124–/127 for the same address counts when you configure an IPv6 prefix in Azure. |
| 187 | +- **Tags**: Apply and update resource tags on public IP prefix resources. |
| 188 | +- **Subscription-scoped listing**: List all public IP prefixes across a subscription. |
| 189 | +- **Multiple prefix lengths**: Create prefixes of different lengths within the same resource group. |
| 190 | +
|
| 191 | +## Limitations |
| 192 | +
|
| 193 | +- **No real IP range allocation**: Public IP Prefix is a mock implementation. No actual IP address ranges are allocated from Azure's public IP pools, and no public internet connectivity is provided. |
| 194 | +- **No IP address derivation**: Creating individual public IP addresses from a prefix is not enforced; both resources are stored independently. |
| 195 | +- **No data persistence**: Public IP prefix resources are not persisted and are lost when the emulator is stopped or restarted. |
| 196 | +
|
| 197 | +## Samples |
| 198 | +
|
| 199 | +The following samples demonstrate how to use Azure Public IP Prefixes with LocalStack for Azure: |
| 200 | +
|
| 201 | +- [Function App and Service Bus](https://github.com/localstack/localstack-azure-samples/tree/main/samples/function-app-service-bus/dotnet/) |
| 202 | +- [Web App and Cosmos DB for MongoDB API](https://github.com/localstack/localstack-azure-samples/tree/main/samples/web-app-cosmosdb-mongodb-api/python/) |
| 203 | +
|
| 204 | +## API Coverage |
| 205 | +
|
| 206 | +<AzureFeatureCoverage service="Microsoft.Network" client:load /> |
0 commit comments