|
| 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 | +VNets are commonly used to model secure, segmented network topologies in cloud environments. |
| 14 | + |
| 15 | +LocalStack for Azure allows you to build and test Virtual Network workflows in your local environment. |
| 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 | +Start your LocalStack container using your preferred method. |
| 23 | +Then start CLI interception: |
| 24 | + |
| 25 | +```bash |
| 26 | +azlocal start_interception |
| 27 | +``` |
| 28 | + |
| 29 | +### Create a resource group |
| 30 | + |
| 31 | +Create a resource group for your networking resources: |
| 32 | + |
| 33 | +```bash |
| 34 | +az group create \ |
| 35 | + --name rg-vnet-demo \ |
| 36 | + --location westeurope |
| 37 | +``` |
| 38 | + |
| 39 | +```bash title="Output" |
| 40 | +{ |
| 41 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo", |
| 42 | + "location": "westeurope", |
| 43 | + "managedBy": null, |
| 44 | + "name": "rg-vnet-demo", |
| 45 | + "properties": { |
| 46 | + "provisioningState": "Succeeded" |
| 47 | + }, |
| 48 | + ... |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +### Create and inspect a virtual network |
| 53 | + |
| 54 | +Create a VNet with a `10.0.0.0/16` address space: |
| 55 | + |
| 56 | +```bash |
| 57 | +az network vnet create \ |
| 58 | + --name vnet-doc78 \ |
| 59 | + --resource-group rg-vnet-demo \ |
| 60 | + --location westeurope \ |
| 61 | + --address-prefixes 10.0.0.0/16 |
| 62 | +``` |
| 63 | + |
| 64 | +```bash title="Output" |
| 65 | +{ |
| 66 | + "newVNet": { |
| 67 | + "name": "vnet-doc78", |
| 68 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo/providers/Microsoft.Network/virtualNetworks/vnet-doc78", |
| 69 | + "location": "westeurope", |
| 70 | + "addressSpace": { |
| 71 | + "addressPrefixes": ["10.0.0.0/16"] |
| 72 | + }, |
| 73 | + "provisioningState": "Succeeded", |
| 74 | + ... |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +Get the VNet details: |
| 80 | + |
| 81 | +```bash |
| 82 | +az network vnet show \ |
| 83 | + --name vnet-doc78 \ |
| 84 | + --resource-group rg-vnet-demo |
| 85 | +``` |
| 86 | + |
| 87 | +```bash title="Output" |
| 88 | +{ |
| 89 | + "name": "vnet-doc78", |
| 90 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo/providers/Microsoft.Network/virtualNetworks/vnet-doc78", |
| 91 | + "location": "westeurope", |
| 92 | + "addressSpace": { |
| 93 | + "addressPrefixes": ["10.0.0.0/16"] |
| 94 | + }, |
| 95 | + "provisioningState": "Succeeded", |
| 96 | + ... |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +### Create and manage subnets |
| 101 | + |
| 102 | +Create a subnet: |
| 103 | + |
| 104 | +```bash |
| 105 | +az network vnet subnet create \ |
| 106 | + --name subnet1 \ |
| 107 | + --resource-group rg-vnet-demo \ |
| 108 | + --vnet-name vnet-doc78 \ |
| 109 | + --address-prefixes 10.0.1.0/24 |
| 110 | +``` |
| 111 | + |
| 112 | +```bash title="Output" |
| 113 | +{ |
| 114 | + "name": "subnet1", |
| 115 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo/providers/Microsoft.Network/virtualNetworks/vnet-doc78/subnets/subnet1", |
| 116 | + "addressPrefix": "10.0.1.0/24", |
| 117 | + "provisioningState": "Succeeded", |
| 118 | + ... |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +Get and list subnets: |
| 123 | + |
| 124 | +```bash |
| 125 | +az network vnet subnet show \ |
| 126 | + --name subnet1 \ |
| 127 | + --resource-group rg-vnet-demo \ |
| 128 | + --vnet-name vnet-doc78 |
| 129 | + |
| 130 | +az network vnet subnet list \ |
| 131 | + --resource-group rg-vnet-demo \ |
| 132 | + --vnet-name vnet-doc78 |
| 133 | +``` |
| 134 | + |
| 135 | +```bash title="Output" |
| 136 | +{ |
| 137 | + "name": "subnet1", |
| 138 | + "addressPrefix": "10.0.1.0/24", |
| 139 | + ... |
| 140 | +} |
| 141 | +[ |
| 142 | + { |
| 143 | + "name": "subnet1", |
| 144 | + "addressPrefix": "10.0.1.0/24", |
| 145 | + ... |
| 146 | + } |
| 147 | +] |
| 148 | +``` |
| 149 | + |
| 150 | +Create a second subnet, delete the first subnet, and list again: |
| 151 | + |
| 152 | +```bash |
| 153 | +az network vnet subnet create \ |
| 154 | + --name subnet2 \ |
| 155 | + --resource-group rg-vnet-demo \ |
| 156 | + --vnet-name vnet-doc78 \ |
| 157 | + --address-prefixes 10.0.2.0/24 |
| 158 | + |
| 159 | +az network vnet subnet delete \ |
| 160 | + --name subnet1 \ |
| 161 | + --resource-group rg-vnet-demo \ |
| 162 | + --vnet-name vnet-doc78 |
| 163 | + |
| 164 | +az network vnet subnet list \ |
| 165 | + --resource-group rg-vnet-demo \ |
| 166 | + --vnet-name vnet-doc78 |
| 167 | +``` |
| 168 | + |
| 169 | +```bash title="Output" |
| 170 | +{ |
| 171 | + "name": "subnet2", |
| 172 | + "addressPrefix": "10.0.2.0/24", |
| 173 | + ... |
| 174 | +} |
| 175 | +[ |
| 176 | + { |
| 177 | + "name": "subnet2", |
| 178 | + "addressPrefix": "10.0.2.0/24", |
| 179 | + ... |
| 180 | + } |
| 181 | +] |
| 182 | +``` |
| 183 | + |
| 184 | +### Update virtual network properties |
| 185 | + |
| 186 | +Update DNS servers and tags on the VNet: |
| 187 | + |
| 188 | +```bash |
| 189 | +az network vnet update \ |
| 190 | + --name vnet-doc78 \ |
| 191 | + --resource-group rg-vnet-demo \ |
| 192 | + --dns-servers 8.8.8.8 8.8.4.4 \ |
| 193 | + --set tags.environment=test tags.project=localstack |
| 194 | +``` |
| 195 | + |
| 196 | +```bash title="Output" |
| 197 | +{ |
| 198 | + "name": "vnet-doc78", |
| 199 | + "dhcpOptions": { |
| 200 | + "dnsServers": ["8.8.8.8", "8.8.4.4"] |
| 201 | + }, |
| 202 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-vnet-demo/providers/Microsoft.Network/virtualNetworks/vnet-doc78", |
| 203 | + "provisioningState": "Succeeded", |
| 204 | + "tags": { |
| 205 | + "environment": "test", |
| 206 | + "project": "localstack" |
| 207 | + }, |
| 208 | + ... |
| 209 | +} |
| 210 | +``` |
| 211 | + |
| 212 | +### Delete and verify |
| 213 | + |
| 214 | +Delete the VNet and verify the list is empty: |
| 215 | + |
| 216 | +```bash |
| 217 | +az network vnet delete \ |
| 218 | + --name vnet-doc78 \ |
| 219 | + --resource-group rg-vnet-demo |
| 220 | + |
| 221 | +az network vnet list --resource-group rg-vnet-demo |
| 222 | +``` |
| 223 | + |
| 224 | +```bash title="Output" |
| 225 | +[] |
| 226 | +``` |
| 227 | + |
| 228 | +## API Coverage |
| 229 | + |
| 230 | +<AzureFeatureCoverage service="Microsoft.Network" client:load /> |
0 commit comments