Tutorial 1 deploy a simple VNet

Alex Buck edited this page Nov 14, 2017 · 14 revisions

This tutorial is the first in a series designed to teach you how to author an Azure Building Blocks settings file to deploy a complex architecture to Azure. The tutorials are progressive, and begin with this tutorial that teaches you how to add a JSON object that deploys a simple VNet to your settings file.

Before You Start

If you haven't done so, read about the Azure Building Block tutorials and follow the steps to create your own settings file. Next, clone the Azure Building Blocks Github repository. Finally, read through the Azure Building Blocks virtual network settings file schema to become familiar with the properties we'll walk through.

Architecture

We'll begin our architecture with a simple virtual network:

Simple virtual network with a single subnet

The architecture includes the following:

  • A VNet named msft-hub-vnet with an address space of 10.0.0.0/16.
  • A subnet within msft-hub-vnet named firewall with an address space of 10.0.1.0/24.

Let's take a look at the JSON settings that specify what we need to deploy the VNet before we add them to our settings file.

Settings file walkthrough

The JSON settings we'll look at are provided in the Azure Building Blocks Github repository. Navigate to the /scenarios folder, then to the /tutorials folder, and open the tutorial-1.json file in an editor such as Visual Studio Code.

{
  "type": "VirtualNetwork",
  "settings": [
    {
      "name": "msft-hub-vnet",
      "addressPrefixes": [
        "10.0.0.0/16"
       ],
      "subnets": [
        {
          "name": "firewall",
          "addressPrefix": "10.0.1.0/24"
        }
      ]
    } 
  ]
}

The type property is used by the Azure Building Blocks to identify the type of building block. We're going to deploy a VNet, so we have to specify a VirtualNetwork building block type. This property is required for each of the building blocks.

Every Azure Building block also requires a settings object where the properties for the building block are specified.

Let's look at each property for a simple VNet:

  • "name"

    In Azure, each resource requires a name to uniquely identify the resource within a resource group. In Azure Building Blocks, you specify a name property for each resource type to provide this unique name. When we deploy this settings file using the command line tool, this is the name that we'll see in the Azure portal user interface. In this settings file we've named the VNet msft-hub-vnet because this in future tutorials this will become the central "hub" VNet for our complex architecture.

  • "addressPrefixes"

    Next, we specify the address space for our virtual network using the addressPrefixes property. The address space is specified using CIDR notation. In our example settings file, we've specified the address space to be 10.0.0.0/16. This means Azure Resource Manager allocates 65536 IP addresses beginning at 10.0.0.0 and ending at 10.0.255.255.

    Notice that the field for specifying the virtual network address space is an array. The reason for this is because we can specify multiple address ranges. For example, in addition to 10.0.0.0/16 we could have also specified 11.0.0.0/16 to specify everything between 11.0.0.0 and 11.0.255.255 as well:

          "addressPrefixes": [
            "10.0.0.0/16",
            "11.0.0.0/16"
           ]
  • "subnets"

    Now that we have specified the address space for our virtual network, we can begin to create named network segments known as subnets. Subnets are used to manage security, routing, and user access for each subnet independently of the entire VNet. Subnets are also used to segment VMs into back-end pools for load balancers and application gateways.

    As you can see from our settings file, we've specified a single subnet named firewall with an address space of 10.0.1.0/24. Note that the subnets property is also an array - we can specify up to 1,000 subnets for each VNet.

Add the JSON object to your settings file

Let's take another look at the empty settings file you created in about the Azure Building Block tutorials:

{
  "$schema": "https://raw.githubusercontent.com/mspnp/template-building-blocks/master/schemas/buildingBlocks.json",
  "contentVersion": "1.0.0.0",
  "parameters" : {
    "buildingBlocks": {
      "value": [
        {}
      ]
    }
  }
}

Currently, the buildingBlocks array is empty. Copy and paste the JSON for the simple VNet from above into it:

{
  "$schema": "https://raw.githubusercontent.com/mspnp/template-building-blocks/master/schemas/buildingBlocks.json",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "buildingBlocks": {
      "value": [
        {
          "type": "VirtualNetwork",
          "settings": [
            {
              "name": "msft-hub-vnet",
              "addressPrefixes": [
                "10.0.0.0/16"
              ],
              "subnets": [
                {
                  "name": "firewall",
                  "addressPrefix": "10.0.1.0/24"
                }
              ]
            }
          ]
        }
      ]
    }
  }
}

Save your settings file. Now let's deploy it to Azure.

Deploy the settings file using Azure Building Blocks

To deploy your settings file, open a command line interface - the same command line interface you used to install the Azure Building Blocks. Navigate to the folder where you've saved your settings file.

Before you can get started, you have to login to the Azure CLI:

az login

You'll be prompted to go to https://aka.ms/devicelogin and enter a code. Once you've successfully logged in, the command prompt reports success and drops you back at the command line.

You'll need a few things before you can deploy the VNet using the settings file. First, you need your Azure subscription ID. You can find your subscription ID using the Azure CLI command az account list, or, by going to the Azure Portal and opening the subscriptions blade.

Next, you'll need to consider the resource group to which the VNet will be deployed. You can deploy to either an existing or new resource group. The Azure Building Blocks command line tool determines if the resource group name you pass with the -g option exists or not. If the resource group exists, the command line tool deploys the VNet to the existing resource group. If it doesn't exist, the command line tool creates the resource group for you and then deploys the VNet to the new resource group.

Finally, you'll also need to consider the Azure region where the VNet will be deployed.

azbb -g <new or existing resource group> -s <subscription ID> -l <region> -p <path to your settings file> --deploy

The command line tool will parse your settings file and deploy it to Azure using Azure Resource Manager. To verify that the VNet was deployed, visit the Azure Portal, click on Resource Groups in the left-hand pane to open the Resource Groups blade, then click on the name of the resource group you specified above. The blade for that resource group will open, and you should see the msft-hub-vnet in the list of resources.

Next steps

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.