Azure Resource Manager (ARM) Quickstart: Virtual Network

This guide demonstrates how to deploy a simple Azure Virtual Network (VNet) using an ARM template. A virtual network is a fundamental building block for your private network in Azure.

Prerequisites

Step 1: Create the ARM Template

Create a file named azuredeploy.json and paste the following JSON content into it. This template defines a virtual network with a single subnet.

{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "virtualNetworkName": { "type": "string", "defaultValue": "myVNet", "metadata": { "description": "Name of the virtual network." } }, "location": { "type": "string", "defaultValue": "[resourceGroup().location]", "metadata": { "description": "Location for the virtual network." } }, "addressPrefix": { "type": "string", "defaultValue": "10.0.0.0/16", "metadata": { "description": "Address space for the virtual network." } }, "subnetName": { "type": "string", "defaultValue": "default", "metadata": { "description": "Name of the subnet." } }, "subnetPrefix": { "type": "string", "defaultValue": "10.0.0.0/24", "metadata": { "description": "Address space for the subnet." } } }, "resources": [ { "type": "Microsoft.Network/virtualNetworks", "apiVersion": "2020-11-01", "name": "[parameters('virtualNetworkName')]", "location": "[parameters('location')]", "properties": { "addressSpace": { "addressPrefixes": [ "[parameters('addressPrefix')]" ] }, "subnets": [ { "name": "[parameters('subnetName')]", "properties": { "addressPrefix": "[parameters('subnetPrefix')]" } } ] } } ], "outputs": { "virtualNetworkName": { "type": "string", "value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]" } } }

Step 2: Create a Parameter File (Optional)

You can override the default parameter values by creating a parameter file named azuredeploy.parameters.json. For example, to use a different name and address prefix:

{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "virtualNetworkName": { "value": "myCustomVNet" }, "addressPrefix": { "value": "10.1.0.0/16" }, "subnetPrefix": { "value": "10.1.1.0/24" } } }

Step 3: Deploy the Template

Use the Azure CLI to deploy the ARM template. Replace MyResourceGroup with the name of your resource group and eastus with the desired Azure region.

az deployment group create --resource-group MyResourceGroup --template-file azuredeploy.json --parameters azuredeploy.parameters.json

If you are not using a parameter file, you can deploy directly using:

az deployment group create --resource-group MyResourceGroup --template-file azuredeploy.json --parameters virtualNetworkName='myVNetFromCLI' addressPrefix='10.2.0.0/16'

Step 4: Verify the Deployment

After the deployment completes, you can verify that the virtual network has been created in the Azure portal or by using the Azure CLI:

az network vnet list --resource-group MyResourceGroup --output table

Clean up Resources

To avoid ongoing charges, delete the resource group if you no longer need the resources:

az group delete --name MyResourceGroup --yes --no-wait

You have successfully deployed a virtual network using an ARM template. This is a basic example, and ARM templates can be used to deploy a wide range of complex Azure resources.

Learn More about ARM Templates