|
| 1 | +--- |
| 2 | +title: "Network Interface" |
| 3 | +description: Get started with Azure Network Interface on LocalStack |
| 4 | +template: doc |
| 5 | +--- |
| 6 | + |
| 7 | +import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage"; |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +Azure Network Interface (NIC) is the interconnection between a virtual machine and a virtual network. |
| 12 | +A NIC enables an Azure VM to communicate with the internet, Azure, and on-premises resources. |
| 13 | +Each NIC can have one or more IP configurations, an associated subnet, optional network security group (NSG), and optional public IP address. For more information, see [Network interfaces](https://learn.microsoft.com/en-us/azure/virtual-network/virtual-network-network-interface). |
| 14 | + |
| 15 | +LocalStack for Azure provides a local environment for building and testing applications that make use of Network Interfaces. |
| 16 | +The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Network Interface's integration with LocalStack. |
| 17 | + |
| 18 | +## Getting started |
| 19 | + |
| 20 | +This guide is designed for users new to Network Interfaces 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 and virtual network |
| 38 | + |
| 39 | +A network interface must be associated with a subnet. Create the prerequisite resources first: |
| 40 | + |
| 41 | +```bash |
| 42 | +az group create \ |
| 43 | + --name rg-nic-demo \ |
| 44 | + --location westeurope |
| 45 | +``` |
| 46 | + |
| 47 | +```bash title="Output" |
| 48 | +{ |
| 49 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo", |
| 50 | + "location": "westeurope", |
| 51 | + "managedBy": null, |
| 52 | + "name": "rg-nic-demo", |
| 53 | + "properties": { |
| 54 | + "provisioningState": "Succeeded" |
| 55 | + }, |
| 56 | + "tags": null, |
| 57 | + "type": "Microsoft.Resources/resourceGroups" |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +Create a virtual network for the network interfaces: |
| 62 | + |
| 63 | +```bash |
| 64 | +az network vnet create \ |
| 65 | + --name vnet-nic-demo \ |
| 66 | + --resource-group rg-nic-demo \ |
| 67 | + --location westeurope \ |
| 68 | + --address-prefixes 10.0.0.0/16 |
| 69 | +``` |
| 70 | + |
| 71 | +```bash title="Output" |
| 72 | +{ |
| 73 | + "newVNet": { |
| 74 | + "addressSpace": { |
| 75 | + "addressPrefixes": [ |
| 76 | + "10.0.0.0/16" |
| 77 | + ] |
| 78 | + }, |
| 79 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/virtualNetworks/vnet-nic-demo", |
| 80 | + "location": "westeurope", |
| 81 | + "name": "vnet-nic-demo", |
| 82 | + "provisioningState": "Succeeded", |
| 83 | + "resourceGroup": "rg-nic-demo", |
| 84 | + "subnets": [], |
| 85 | + "type": "Microsoft.Network/virtualNetworks", |
| 86 | + ... |
| 87 | + } |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | + |
| 92 | +Create a subnet within the virtual network to attach the NICs to: |
| 93 | + |
| 94 | +```bash |
| 95 | +az network vnet subnet create \ |
| 96 | + --name subnet-nic \ |
| 97 | + --resource-group rg-nic-demo \ |
| 98 | + --vnet-name vnet-nic-demo \ |
| 99 | + --address-prefixes 10.0.1.0/24 |
| 100 | +``` |
| 101 | + |
| 102 | +```bash title="Output" |
| 103 | +{ |
| 104 | + "addressPrefix": "10.0.1.0/24", |
| 105 | + "delegations": [], |
| 106 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/virtualNetworks/vnet-nic-demo/subnets/subnet-nic", |
| 107 | + "name": "subnet-nic", |
| 108 | + "privateEndpointNetworkPolicies": "Disabled", |
| 109 | + "privateLinkServiceNetworkPolicies": "Enabled", |
| 110 | + "provisioningState": "Succeeded", |
| 111 | + "resourceGroup": "rg-nic-demo", |
| 112 | + "type": "Microsoft.Network/virtualNetworks/subnets" |
| 113 | +... |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +### Create a network interface |
| 118 | + |
| 119 | +Create a NIC attached to the subnet: |
| 120 | + |
| 121 | +```bash |
| 122 | +az network nic create \ |
| 123 | + --name nic-demo \ |
| 124 | + --resource-group rg-nic-demo \ |
| 125 | + --location westeurope \ |
| 126 | + --vnet-name vnet-nic-demo \ |
| 127 | + --subnet subnet-nic |
| 128 | +``` |
| 129 | + |
| 130 | +```bash title="Output" |
| 131 | +{ |
| 132 | + "NewNIC": { |
| 133 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/networkInterfaces/nic-demo", |
| 134 | + "ipConfigurations": [ |
| 135 | + { |
| 136 | + "name": "ipconfig1", |
| 137 | + "primary": true, |
| 138 | + "privateIPAddress": "10.0.1.4", |
| 139 | + "privateIPAddressVersion": "IPv4", |
| 140 | + "privateIPAllocationMethod": "Dynamic", |
| 141 | + "provisioningState": "Succeeded", |
| 142 | + "resourceGroup": "rg-nic-demo", |
| 143 | + "subnet": { |
| 144 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/virtualNetworks/vnet-nic-demo/subnets/subnet-nic", |
| 145 | + "resourceGroup": "rg-nic-demo" |
| 146 | + }, |
| 147 | + ... |
| 148 | + } |
| 149 | + ], |
| 150 | + "location": "westeurope", |
| 151 | + "name": "nic-demo", |
| 152 | + "provisioningState": "Succeeded", |
| 153 | + "resourceGroup": "rg-nic-demo", |
| 154 | + "type": "Microsoft.Network/networkInterfaces", |
| 155 | + ... |
| 156 | + } |
| 157 | +} |
| 158 | +``` |
| 159 | + |
| 160 | +### Create a NIC with a static private IP |
| 161 | + |
| 162 | +Create a second network interface and assign a static private IP address from the subnet: |
| 163 | + |
| 164 | +```bash |
| 165 | +az network nic create \ |
| 166 | + --name nic-static \ |
| 167 | + --resource-group rg-nic-demo \ |
| 168 | + --location westeurope \ |
| 169 | + --vnet-name vnet-nic-demo \ |
| 170 | + --subnet subnet-nic \ |
| 171 | + --private-ip-address 10.0.1.10 |
| 172 | +``` |
| 173 | + |
| 174 | +```bash title="Output" |
| 175 | +{ |
| 176 | + "NewNIC": { |
| 177 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/networkInterfaces/nic-static", |
| 178 | + "ipConfigurations": [ |
| 179 | + { |
| 180 | + "name": "ipconfig1", |
| 181 | + "primary": true, |
| 182 | + "privateIPAddress": "10.0.1.10", |
| 183 | + "privateIPAddressVersion": "IPv4", |
| 184 | + "privateIPAllocationMethod": "Static", |
| 185 | + "provisioningState": "Succeeded", |
| 186 | + "subnet": { |
| 187 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/virtualNetworks/vnet-nic-demo/subnets/subnet-nic", |
| 188 | + "resourceGroup": "rg-nic-demo" |
| 189 | + }, |
| 190 | + ... |
| 191 | + } |
| 192 | + ], |
| 193 | + "location": "westeurope", |
| 194 | + "name": "nic-static", |
| 195 | + "provisioningState": "Succeeded", |
| 196 | + "resourceGroup": "rg-nic-demo", |
| 197 | + "type": "Microsoft.Network/networkInterfaces", |
| 198 | + ... |
| 199 | + } |
| 200 | +} |
| 201 | +``` |
| 202 | + |
| 203 | +### Get and list network interfaces |
| 204 | + |
| 205 | +Retrieve the details of a network interface and list all NICs in the resource group: |
| 206 | + |
| 207 | +```bash |
| 208 | +az network nic show \ |
| 209 | + --name nic-demo \ |
| 210 | + --resource-group rg-nic-demo |
| 211 | +``` |
| 212 | + |
| 213 | +```bash title="Output" |
| 214 | +{ |
| 215 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/networkInterfaces/nic-demo", |
| 216 | + "ipConfigurations": [ |
| 217 | + { |
| 218 | + "name": "ipconfig1", |
| 219 | + "primary": true, |
| 220 | + "privateIPAddress": "10.0.1.4", |
| 221 | + "privateIPAddressVersion": "IPv4", |
| 222 | + "privateIPAllocationMethod": "Dynamic", |
| 223 | + "provisioningState": "Succeeded", |
| 224 | + "subnet": { |
| 225 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/virtualNetworks/vnet-nic-demo/subnets/subnet-nic", |
| 226 | + "resourceGroup": "rg-nic-demo" |
| 227 | + }, |
| 228 | + ... |
| 229 | + } |
| 230 | + ], |
| 231 | + "location": "westeurope", |
| 232 | + "name": "nic-demo", |
| 233 | + "provisioningState": "Succeeded", |
| 234 | + "resourceGroup": "rg-nic-demo", |
| 235 | + "type": "Microsoft.Network/networkInterfaces", |
| 236 | + ... |
| 237 | +} |
| 238 | +``` |
| 239 | + |
| 240 | + |
| 241 | +Then list all network interfaces in the resource group: |
| 242 | + |
| 243 | +```bash |
| 244 | +az network nic list \ |
| 245 | + --resource-group rg-nic-demo |
| 246 | +``` |
| 247 | + |
| 248 | +```bash title="Output" |
| 249 | +[ |
| 250 | + { |
| 251 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/networkInterfaces/nic-demo", |
| 252 | + "ipConfigurations": [ { "name": "ipconfig1", "privateIPAllocationMethod": "Dynamic", ... } ], |
| 253 | + "location": "westeurope", |
| 254 | + "name": "nic-demo", |
| 255 | + "provisioningState": "Succeeded", |
| 256 | + "type": "Microsoft.Network/networkInterfaces", |
| 257 | + ... |
| 258 | + }, |
| 259 | + { |
| 260 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-nic-demo/providers/Microsoft.Network/networkInterfaces/nic-static", |
| 261 | + "ipConfigurations": [ { "name": "ipconfig1", "privateIPAddress": "10.0.1.10", "privateIPAllocationMethod": "Static", ... } ], |
| 262 | + "location": "westeurope", |
| 263 | + "name": "nic-static", |
| 264 | + "provisioningState": "Succeeded", |
| 265 | + "type": "Microsoft.Network/networkInterfaces", |
| 266 | + ... |
| 267 | + } |
| 268 | +] |
| 269 | +``` |
| 270 | +
|
| 271 | +### Delete a network interface |
| 272 | +
|
| 273 | +Delete the network interface and verify it no longer appears in the list: |
| 274 | +
|
| 275 | +```bash |
| 276 | +az network nic delete \ |
| 277 | + --name nic-demo \ |
| 278 | + --resource-group rg-nic-demo |
| 279 | +``` |
| 280 | +
|
| 281 | +## Features |
| 282 | +
|
| 283 | +The Network Interface emulator supports the following features: |
| 284 | +
|
| 285 | +- **Create and manage NICs**: Full lifecycle management including create, get, update, list, and delete. |
| 286 | +- **Dynamic IP allocation**: Automatically assigns a private IP address from the associated subnet address space. |
| 287 | +- **Static IP configuration**: Assign a fixed private IP address from the subnet range. |
| 288 | +- **Public IP association**: Attach a public IP address resource to a NIC IP configuration. |
| 289 | +- **NSG association**: Associate a network security group with a NIC. |
| 290 | +- **IP forwarding**: Configure IP forwarding on the NIC for routing scenarios. |
| 291 | +- **Accelerated networking**: Store and return the `enableAcceleratedNetworking` flag. |
| 292 | +- **Tags**: Apply and update resource tags. |
| 293 | +- **Subscription-scoped listing**: List all NICs across a subscription. |
| 294 | +
|
| 295 | +## Limitations |
| 296 | +
|
| 297 | +- **No actual networking**: Network Interface is a mock implementation. State is persisted in memory and returned faithfully, but no network packets are routed through the interface. |
| 298 | +- **No VM attachment enforcement**: Associating a NIC with a virtual machine is accepted but VM resources are not implemented. |
| 299 | +- **No data persistence**: NIC resources are not persisted and are lost when the emulator is stopped or restarted. |
| 300 | +
|
| 301 | +## Samples |
| 302 | +
|
| 303 | +The following samples demonstrate how to use Azure Network Interfaces with LocalStack for Azure: |
| 304 | +
|
| 305 | +- [Function App and Service Bus](https://github.com/localstack/localstack-azure-samples/tree/main/samples/function-app-service-bus/dotnet/) |
| 306 | +- [Web App and Cosmos DB for MongoDB API](https://github.com/localstack/localstack-azure-samples/tree/main/samples/web-app-cosmosdb-mongodb-api/python) |
| 307 | +
|
| 308 | +## API Coverage |
| 309 | +
|
| 310 | +<AzureFeatureCoverage service="Microsoft.Network" client:load /> |
0 commit comments