Create a virtual network using an Azure Resource Manager template

An Azure virtual network (VNet) is a representation of your own network in the cloud. You can control your Azure network settings and define DHCP address blocks, DNS settings, security policies, and routing. You can also further segment your VNet into subnets and deploy Azure IaaS virtual machines (VMs) and PaaS role instances, in the same way you can deploy physical and virtual machines to your on-premises datacenter. In essence, you can expand your network to Azure, bringing your own IP address blocks. Read the virtual network overview if you are not familiar with VNets.

Azure has two deployment models: Azure Resource Manager and classic. Microsoft recommends creating resources through the Resource Manager deployment model. To learn more about the differences between the two models, read the Understand Azure deployment models article.

This article explains how to create a VNet through the Resource Manager deployment model using an Azure Resource Manager template. You can also create a VNet through Resource Manager using other tools or create a VNet through the classic deployment model by selecting a different option from the following list:

You will learn how to download and modify and existing ARM template from GitHub, and deploy the template from GitHub, PowerShell, and the Azure CLI.

If you are simply deploying the ARM template directly from GitHub, without any changes, skip to deploy a template from github.

Scenario

To better illustrate how to create a VNet and subnets, this document will use the scenario below.

VNet scenario

In this scenario you will create a VNet named TestVNet with a reserved CIDR block of 192.168.0.0./16. Your VNet will contain the following subnets:

  • FrontEnd, using 192.168.1.0/24 as its CIDR block.
  • BackEnd, using 192.168.2.0/24 as its CIDR block.

Download and understand the Azure Resource Manager template

You can download the existing template for creating a VNet and two subnets from GitHub, make any changes you might want, and reuse it. To do so, complete the following steps:

  1. Navigate to the sample template page.
  2. Click azuredeploy.json, and then click RAW.
  3. Save the file to a a local folder on your computer.
  4. If you are familiar with templates, skip to step 7.
  5. Open the file you just saved and look at the contents under parameters in line 5. ARM template parameters provide a placeholder for values that can be filled out during deployment.

    Parameter Description
    location Azure region where the VNet will be created
    vnetName Name for the new VNet
    addressPrefix Address space for the VNet, in CIDR format
    subnet1Name Name for the first VNet
    subnet1Prefix CIDR block for the first subnet
    subnet2Name Name for the second VNet
    subnet2Prefix CIDR block for the second subnet
    Important

    Azure Resource Manager templates maintained in GitHub can change over time. Make sure you check the template before using it.

  6. Check the content under resources and notice the following:

    • type. Type of resource being created by the template. In this case, Microsoft.Network/virtualNetworks, which represent a VNet.
    • name. Name for the resource. Notice the use of [parameters('vnetName')], which means the name will provided as input by the user or a parameter file during deployment.
    • properties. List of properties for the resource. This template uses the address space and subnet properties during VNet creation.
  7. Navigate back to the sample template page.
  8. Click azuredeploy-paremeters.json, and then click RAW.
  9. Save the file to a a local folder on your computer.
  10. Open the file you just saved and edit the values for the parameters. Use the following values below to deploy the VNet described in the scenario:

        {
          "location": {
            "value": "Central US"
          },
          "vnetName": {
              "value": "TestVNet"
          },
          "addressPrefix": {
              "value": "192.168.0.0/16"
          },
          "subnet1Name": {
              "value": "FrontEnd"
          },
          "subnet1Prefix": {
            "value": "192.168.1.0/24"
          },
          "subnet2Name": {
              "value": "BackEnd"
          },
          "subnet2Prefix": {
              "value": "192.168.2.0/24"
          }
        }
    
  11. Save the file.

Deploy the template using PowerShell

Complete the following steps to deploy the template you downloaded by using PowerShell:

  1. Install and configure Azure PowerShell by completing the steps in the How to Install and Configure Azure PowerShell article.
  2. Run the following command to create a new resource group:

    New-AzureRmResourceGroup -Name TestRG -Location centralus
    

    The command creates a resource group named TestRG in the Central US azure region. For more information about resource groups, visit Azure Resource Manager Overview.

    Expected output:

     ResourceGroupName : TestRG
     Location          : centralus
     ProvisioningState : Succeeded
     Tags              :
     Permissions       :
                         Actions  NotActions
                         =======  ==========
                         *
     ResourceId        : /subscriptions/[Id]/resourceGroups/TestRG
    
  3. Run the following command to deploy the new VNet using the template and parameter files you downloaded and modified above:

    New-AzureRmResourceGroupDeployment -Name TestVNetDeployment -ResourceGroupName TestRG `
    -TemplateFile C:\ARM\azuredeploy.json -TemplateParameterFile C:\ARM\azuredeploy-parameters.json
    

    Expected output:

     DeploymentName    : TestVNetDeployment
     ResourceGroupName : TestRG
     ProvisioningState : Succeeded
     Timestamp         : [Date and time]
     Mode              : Incremental
     TemplateLink      :
     Parameters        :
                         Name             Type                       Value
                         ===============  =========================  ==========
                         location         String                     Central US
                         vnetName         String                     TestVNet
                         addressPrefix    String                     192.168.0.0/16
                         subnet1Prefix    String                     192.168.1.0/24
                         subnet1Name      String                     FrontEnd
                         subnet2Prefix    String                     192.168.2.0/24
                         subnet2Name      String                     BackEnd
    
     Outputs           :
    
  4. Run the following command to view the properties of the new VNet:

    Get-AzureRmVirtualNetwork -ResourceGroupName TestRG -Name TestVNet
    

    Expected output:

     Name              : TestVNet
     ResourceGroupName : TestRG
     Location          : centralus
     Id                : /subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet
     Etag              : W/"[Id]"
     ProvisioningState : Succeeded
     Tags              :
     AddressSpace      : {
                           "AddressPrefixes": [
                             "192.168.0.0/16"
                           ]
                         }
     DhcpOptions       : {
                           "DnsServers": null
                         }
     NetworkInterfaces : null
     Subnets           : [
                           {
                             "Name": "FrontEnd",
                             "Etag": "W/\"[Id]\"",
                             "Id": "/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/FrontEnd",
                             "AddressPrefix": "192.168.1.0/24",
                             "IpConfigurations": [],
                             "NetworkSecurityGroup": null,
                             "RouteTable": null,
                             "ProvisioningState": "Succeeded"
                           },
                           {
                             "Name": "BackEnd",
                             "Etag": "W/\"[Id]\"",
                             "Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/BackEnd",
                             "AddressPrefix": "192.168.2.0/24",
                             "IpConfigurations": [],
                             "NetworkSecurityGroup": null,
                             "RouteTable": null,
                             "ProvisioningState": "Succeeded"
                           }
                         ]
    

Deploy the template using click-to-deploy

You can reuse pre-defined Azure Resource Manager templates uploaded to a GitHub repository maintained by Microsoft and open to the community. These templates can be deployed straight out of GitHub, or downloaded and modified to fit your needs. To deploy a template that creates a VNet with two subnets, complete the following steps:

  1. From a browser, navigate to https://github.com/Azure/azure-quickstart-templates.
  2. Scroll down the list of templates, and click 101-vnet-two-subnets. Check the README.md file, as shown below.

    READEME.md file in github

  3. Click Deploy to Azure. If necessary, enter your Azure login credentials.

  4. In the Parameters blade, enter the values you want to use to create your new VNet, and then click OK. The following figure shows the values for the scenario:

    ARM template parameters

  5. Click Resource group and select a resource group to add the VNet to, or click Create new to add the VNet to a new resource group. The following figure shows the resource group settings for a new resource group called TestRG:

    Resource group

  6. If necessary, change the Subscription and Location settings for your VNet.

  7. If you do not want to see the VNet as a tile in the Startboard, disable Pin to Startboard.
  8. Click Legal terms, read the terms, and click Buy to agree.
  9. Click Create to create the VNet.

    Submitting deployment tile in preview portal

  10. Once the deployment is complete, in the Azure portal click More services, type virtual networks in the filter box that appears, then click Virtual networks to see the Virtual networks blade. In the blade, click TestVNet. In the TestVNet blade, click Subnets to see the created subnets, as shown in the following picture:

    Create VNet in preview portal

Next steps

Learn how to connect: