Quickstart: Create a virtual network - Bicep

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

Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources. It provides concise syntax, reliable type safety, and support for code reuse. Bicep offers the best authoring experience for your infrastructure-as-code solutions in Azure.


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

Review the Bicep file

The Bicep file used in this quickstart is from Azure Quickstart Templates

@description('VNet name')
param vnetName string = 'VNet1'

@description('Address prefix')
param vnetAddressPrefix string = ''

@description('Subnet 1 Prefix')
param subnet1Prefix string = ''

@description('Subnet 1 Name')
param subnet1Name string = 'Subnet1'

@description('Subnet 2 Prefix')
param subnet2Prefix string = ''

@description('Subnet 2 Name')
param subnet2Name string = 'Subnet2'

@description('Location for all resources.')
param location string = resourceGroup().location

resource vnet 'Microsoft.Network/virtualNetworks@2021-08-01' = {
  name: vnetName
  location: location
  properties: {
    addressSpace: {
      addressPrefixes: [
    subnets: [
        name: subnet1Name
        properties: {
          addressPrefix: subnet1Prefix
        name: subnet2Name
        properties: {
          addressPrefix: subnet2Prefix

The following Azure resources have been defined in the Bicep file:

Deploy the Bicep file

  1. Save the Bicep file as main.bicep to your local computer.

  2. Deploy the Bicep file using either Azure CLI or Azure PowerShell.

    az group create --name exampleRG --location eastus
    az deployment group create --resource-group exampleRG --template-file main.bicep

    When the deployment finishes, you should see a message indicating the deployment succeeded.

Review deployed resources

Use Azure CLI or Azure PowerShell to review the deployed resources.

az resource list --resource-group exampleRG

You can use the Azure portal to explore the resources by browsing the settings blades for VNet1.

  1. On the Overview tab, you will see the defined address space of
  2. On the Subnets tab, you will see the deployed subnets of Subnet1 and Subnet2 with the appropriate values from the Bicep file.

Clean up resources

When you no longer need the resources that you created with the virtual network, use Azure portal, Azure CLI, or Azure PowerShell to delete the resource group. This removes the virtual network and all the related resources.

az group delete --name exampleRG

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.