|
| 1 | +--- |
| 2 | +title: "Virtual Network" |
| 3 | +description: Get started with Azure Virtual Network on LocalStack |
| 4 | +template: doc |
| 5 | +--- |
| 6 | + |
| 7 | +import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage"; |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +Azure Virtual Network (VNet) is the core networking service for isolating and routing Azure resources in private IP address spaces. |
| 12 | +It lets you define address ranges, create subnets, and control network behavior for applications. |
| 13 | +Virtual networks are commonly used to model secure, segmented network topologies in cloud environments. For more information, see [What is Azure Virtual Network?](https://learn.microsoft.com/en-us/azure/virtual-network/virtual-networks-overview). |
| 14 | + |
| 15 | +LocalStack for Azure provides a local environment to build and test Azure networking resources, such as virtual networks, private endpoints, and private DNS zones. |
| 16 | +The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Virtual Network's integration with LocalStack. |
| 17 | + |
| 18 | +## Getting started |
| 19 | + |
| 20 | +This guide is designed for users new to Virtual Network 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 | + |
| 25 | +### Create a resource group |
| 26 | + |
| 27 | +Create a resource group for your networking resources: |
| 28 | + |
| 29 | +```bash |
| 30 | +az group create \ |
| 31 | + --name rg-vnet-demo \ |
| 32 | + --location westeurope |
| 33 | +``` |
| 34 | + |
| 35 | +```bash title="Output" |
| 36 | +{ |
| 37 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo", |
| 38 | + "location": "westeurope", |
| 39 | + "managedBy": null, |
| 40 | + "name": "rg-vnet-demo", |
| 41 | + "properties": { |
| 42 | + "provisioningState": "Succeeded" |
| 43 | + }, |
| 44 | + ... |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +### Create and inspect a virtual network |
| 49 | + |
| 50 | +Create a virtual network with a `10.0.0.0/16` address space: |
| 51 | + |
| 52 | +```bash |
| 53 | +az network vnet create \ |
| 54 | + --name vnet-doc78 \ |
| 55 | + --resource-group rg-vnet-demo \ |
| 56 | + --location westeurope \ |
| 57 | + --address-prefixes 10.0.0.0/16 |
| 58 | +``` |
| 59 | + |
| 60 | +```bash title="Output" |
| 61 | +{ |
| 62 | + "newVNet": { |
| 63 | + "name": "vnet-doc78", |
| 64 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo/providers/Microsoft.Network/virtualNetworks/vnet-doc78", |
| 65 | + "location": "westeurope", |
| 66 | + "addressSpace": { |
| 67 | + "addressPrefixes": ["10.0.0.0/16"] |
| 68 | + }, |
| 69 | + "provisioningState": "Succeeded", |
| 70 | + ... |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +Get the virtual network (VNet) details: |
| 76 | + |
| 77 | +```bash |
| 78 | +az network vnet show \ |
| 79 | + --name vnet-doc78 \ |
| 80 | + --resource-group rg-vnet-demo |
| 81 | +``` |
| 82 | + |
| 83 | +```bash title="Output" |
| 84 | +{ |
| 85 | + "name": "vnet-doc78", |
| 86 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo/providers/Microsoft.Network/virtualNetworks/vnet-doc78", |
| 87 | + "location": "westeurope", |
| 88 | + "addressSpace": { |
| 89 | + "addressPrefixes": ["10.0.0.0/16"] |
| 90 | + }, |
| 91 | + "provisioningState": "Succeeded", |
| 92 | + ... |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### Create and manage subnets |
| 97 | + |
| 98 | +Create a subnet: |
| 99 | + |
| 100 | +```bash |
| 101 | +az network vnet subnet create \ |
| 102 | + --name subnet1 \ |
| 103 | + --resource-group rg-vnet-demo \ |
| 104 | + --vnet-name vnet-doc78 \ |
| 105 | + --address-prefixes 10.0.1.0/24 |
| 106 | +``` |
| 107 | + |
| 108 | +```bash title="Output" |
| 109 | +{ |
| 110 | + "name": "subnet1", |
| 111 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo/providers/Microsoft.Network/virtualNetworks/vnet-doc78/subnets/subnet1", |
| 112 | + "addressPrefix": "10.0.1.0/24", |
| 113 | + "provisioningState": "Succeeded", |
| 114 | + ... |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +Retrieve new subnet details and list all VNet subnets |
| 119 | + |
| 120 | +```bash |
| 121 | +az network vnet subnet show \ |
| 122 | + --name subnet1 \ |
| 123 | + --resource-group rg-vnet-demo \ |
| 124 | + --vnet-name vnet-doc78 |
| 125 | + |
| 126 | +az network vnet subnet list \ |
| 127 | + --resource-group rg-vnet-demo \ |
| 128 | + --vnet-name vnet-doc78 |
| 129 | +``` |
| 130 | + |
| 131 | +```bash title="Output" |
| 132 | +{ |
| 133 | + "name": "subnet1", |
| 134 | + "addressPrefix": "10.0.1.0/24", |
| 135 | + ... |
| 136 | +} |
| 137 | +[ |
| 138 | + { |
| 139 | + "name": "subnet1", |
| 140 | + "addressPrefix": "10.0.1.0/24", |
| 141 | + ... |
| 142 | + } |
| 143 | +] |
| 144 | +``` |
| 145 | + |
| 146 | +Add a second subnet to the virtual network, remove the first , and relist all subnets: |
| 147 | + |
| 148 | +```bash |
| 149 | +az network vnet subnet create \ |
| 150 | + --name subnet2 \ |
| 151 | + --resource-group rg-vnet-demo \ |
| 152 | + --vnet-name vnet-doc78 \ |
| 153 | + --address-prefixes 10.0.2.0/24 |
| 154 | + |
| 155 | +az network vnet subnet delete \ |
| 156 | + --name subnet1 \ |
| 157 | + --resource-group rg-vnet-demo \ |
| 158 | + --vnet-name vnet-doc78 |
| 159 | + |
| 160 | +az network vnet subnet list \ |
| 161 | + --resource-group rg-vnet-demo \ |
| 162 | + --vnet-name vnet-doc78 |
| 163 | +``` |
| 164 | + |
| 165 | +```bash title="Output" |
| 166 | +{ |
| 167 | + "name": "subnet2", |
| 168 | + "addressPrefix": "10.0.2.0/24", |
| 169 | + ... |
| 170 | +} |
| 171 | +[ |
| 172 | + { |
| 173 | + "name": "subnet2", |
| 174 | + "addressPrefix": "10.0.2.0/24", |
| 175 | + ... |
| 176 | + } |
| 177 | +] |
| 178 | +``` |
| 179 | + |
| 180 | +### Update virtual network properties |
| 181 | + |
| 182 | +Update DNS servers and tags on the VNet: |
| 183 | + |
| 184 | +```bash |
| 185 | +az network vnet update \ |
| 186 | + --name vnet-doc78 \ |
| 187 | + --resource-group rg-vnet-demo \ |
| 188 | + --dns-servers 8.8.8.8 8.8.4.4 \ |
| 189 | + --set tags.environment=test tags.project=localstack |
| 190 | +``` |
| 191 | + |
| 192 | +```bash title="Output" |
| 193 | +{ |
| 194 | + "name": "vnet-doc78", |
| 195 | + "dhcpOptions": { |
| 196 | + "dnsServers": ["8.8.8.8", "8.8.4.4"] |
| 197 | + }, |
| 198 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo/providers/Microsoft.Network/virtualNetworks/vnet-doc78", |
| 199 | + "provisioningState": "Succeeded", |
| 200 | + "tags": { |
| 201 | + "environment": "test", |
| 202 | + "project": "localstack" |
| 203 | + }, |
| 204 | + ... |
| 205 | +} |
| 206 | +``` |
| 207 | + |
| 208 | +### Delete and verify |
| 209 | + |
| 210 | +Delete the VNet and validate that no virtual networks remain in the resource group: |
| 211 | + |
| 212 | +```bash |
| 213 | +az network vnet delete \ |
| 214 | + --name vnet-doc78 \ |
| 215 | + --resource-group rg-vnet-demo |
| 216 | + |
| 217 | +az network vnet list --resource-group rg-vnet-demo |
| 218 | +``` |
| 219 | + |
| 220 | +```bash title="Output" |
| 221 | +[] |
| 222 | +``` |
| 223 | +## Features |
| 224 | + |
| 225 | +The Virtual Network emulator supports the following features: |
| 226 | + |
| 227 | +- **Virtual networks**: Create, update, delete, list, and get virtual networks with configurable address spaces, DNS servers, and DDoS protection settings. |
| 228 | +- **Subnets**: Full lifecycle management of subnets within virtual networks, including address prefix allocation, service endpoint configuration, and NSG/route table associations. |
| 229 | +- **Network security groups**: Create and manage network security groups with custom security rules. Default rules (AllowVnetInBound, AllowAzureLoadBalancerInBound, DenyAllInBound, AllowVnetOutBound, AllowInternetOutBound, DenyAllOutBound) are automatically provisioned. |
| 230 | +- **Route tables**: Create and manage route tables with custom route entries supporting next hop types such as VirtualAppliance, VirtualNetworkGateway, Internet, and VnetLocal. |
| 231 | +- **Public IP addresses**: Create and manage public IP addresses with Static or Dynamic allocation methods, Standard or Basic SKUs, and availability zone configuration. |
| 232 | +- **Public IP prefixes**: Create and manage public IP prefixes with configurable prefix lengths and SKU settings. |
| 233 | +- **NAT gateways**: Create and manage NAT gateways with public IP address and public IP prefix associations. |
| 234 | +- **Network interfaces**: Create and manage network interfaces with IP configurations, dynamic IP allocation from subnets, accelerated networking, and IP forwarding settings. |
| 235 | +- **Private DNS zones**: Create and manage private DNS zones with virtual network links, registration enablement, and A record sets. |
| 236 | +- **Private endpoints**: Create and manage private endpoints with automatic network interface provisioning, private link service connections, and private DNS zone group integration. |
| 237 | +- **Bastion hosts**: Create and manage bastion hosts with IP configuration validation, SKU selection (Basic, Standard, Premium), and scale unit configuration. |
| 238 | + |
| 239 | +## Limitations |
| 240 | + |
| 241 | +- **No network traffic routing**: The emulator does not route network traffic or enforce security rules. Resources are stored and returned with correct metadata, but no packet-level behavior is applied. |
| 242 | +- **IPv6**: IPv6 fields are accepted in requests but are not functional. All IP allocation operates on IPv4 address spaces only. |
| 243 | +- **Private DNS record types**: Only A record sets are supported in private DNS zones. Other record types (CNAME, MX, TXT, SRV, AAAA) are not available. |
| 244 | +- **Public IP addresses**: Addresses are locally generated and do not represent routable IPs on the public internet. |
| 245 | +- **Bastion host connectivity**: Feature flags such as tunneling, file copy, and Kerberos authentication are stored as configuration but do not provide actual connectivity. |
| 246 | +- **VNet peering**: Virtual network peering is not supported. |
| 247 | +- **VPN and ExpressRoute gateways**: VPN gateways and ExpressRoute circuits are not implemented. |
| 248 | +- **Load balancers**: Azure Load Balancer resources are not implemented. |
| 249 | +- **Application gateways**: Application Gateway resources are not implemented. |
| 250 | +- **Network watchers**: Network Watcher and flow log resources are not implemented. |
| 251 | +- **No data persistence**: Network resources are not persisted and are lost when the emulator is stopped or restarted. |
| 252 | + |
| 253 | +## Samples |
| 254 | + |
| 255 | +The following samples demonstrate how to use Virtual Network with LocalStack for Azure: |
| 256 | + |
| 257 | +- [Function App and Service Bus](https://github.com/localstack/localstack-azure-samples/tree/main/samples/function-app-service-bus/dotnet/) |
| 258 | +- [Web App and Cosmos DB for MongoDB API](https://github.com/localstack/localstack-azure-samples/tree/main/samples/web-app-cosmosdb-mongodb-api/python/) |
| 259 | + |
| 260 | +## API Coverage |
| 261 | + |
| 262 | +<AzureFeatureCoverage service="Microsoft.Network" client:load /> |
0 commit comments