Quickstart: Use a Resource Manager template to create a virtual network

In this quickstart, you learn how to create a virtual network with two subnets by using an Azure Resource Manager template. A virtual network is the fundamental building block for your private network in Azure. It enables Azure resources, like virtual machines (VMs), to securely communicate with each other and with the internet.

Diagram of resources created in the virtual network quickstart.

An Azure Resource Manager template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. You describe your intended deployment without writing the sequence of programming commands to create the deployment.

You can also complete this quickstart by using the Azure portal, Azure PowerShell, or the Azure CLI.

Prerequisites

If you don't have an Azure subscription, create a free account before you begin.

Review the template

The template that you use in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.6.18.56646",
      "templateHash": "10806234693722113459"
    }
  },
  "parameters": {
    "vnetName": {
      "type": "string",
      "defaultValue": "VNet1",
      "metadata": {
        "description": "VNet name"
      }
    },
    "vnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/16",
      "metadata": {
        "description": "Address prefix"
      }
    },
    "subnet1Prefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/24",
      "metadata": {
        "description": "Subnet 1 Prefix"
      }
    },
    "subnet1Name": {
      "type": "string",
      "defaultValue": "Subnet1",
      "metadata": {
        "description": "Subnet 1 Name"
      }
    },
    "subnet2Prefix": {
      "type": "string",
      "defaultValue": "10.0.1.0/24",
      "metadata": {
        "description": "Subnet 2 Prefix"
      }
    },
    "subnet2Name": {
      "type": "string",
      "defaultValue": "Subnet2",
      "metadata": {
        "description": "Subnet 2 Name"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2021-08-01",
      "name": "[parameters('vnetName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('vnetAddressPrefix')]"
          ]
        },
        "subnets": [
          {
            "name": "[parameters('subnet1Name')]",
            "properties": {
              "addressPrefix": "[parameters('subnet1Prefix')]"
            }
          },
          {
            "name": "[parameters('subnet2Name')]",
            "properties": {
              "addressPrefix": "[parameters('subnet2Prefix')]"
            }
          }
        ]
      }
    }
  ]
}

The template defines the following Azure resources:

Deploy the template

Deploy the Resource Manager template to Azure:

  1. Select Deploy to Azure to sign in to Azure and open the template. The template creates a virtual network with two subnets.

    Button to deploy the Resource Manager template to Azure.

  2. In the portal, on the Create a Virtual Network with two Subnets page, enter or select the following values:

    • Resource group: Select Create new, enter CreateVNetQS-rg for the resource group name, and then select OK.
    • Virtual Network Name: Enter a name for the new virtual network.
  3. Select Review + create, and then select Create.

  4. When deployment finishes, select the Go to resource button to review the resources that you deployed.

Review deployed resources

Explore the resources that you created with the virtual network by browsing through the settings panes for VNet1:

  • The Overview tab shows the defined address space of 10.0.0.0/16.

  • The Subnets tab shows the deployed subnets of Subnet1 and Subnet2 with the appropriate values from the template.

To learn about the JSON syntax and properties for a virtual network in a template, see Microsoft.Network/virtualNetworks.

Clean up resources

When you no longer need the resources that you created with the virtual network, delete the resource group. This action removes the virtual network and all the related resources.

To delete the resource group, call the Remove-AzResourceGroup cmdlet:

Remove-AzResourceGroup -Name <your resource group name>

Next steps

In this quickstart, you deployed an Azure virtual network with two subnets. To learn more about Azure virtual networks, continue to the tutorial for virtual networks: