Deploying Multiple Resources Using an Azure JSON File

Posted on by Aidan Finn in Cloud Computing

 

This post will show you how to deploy multiple resources in a fairly simple example of an Azure Resource Manager JSON file, which was created in the following posts:

 

The Starting Point

We will start with a pretty simple JSON that deploys a storage account into a resource group. The template asks, using parameters, the administrator to name the storage account and select a resiliency level for the Standard Storage (HDD) account. A variable (RGLocation) retrieves the Azure region of the desired resource group and is used to automatically place the new storage account into the same Azure region.

Expanding the JSON Template

I want to add some resources to this JSON:

  • A virtual network
  • An availability set

I could learn how to build out the syntax of these resources, but the snippets functionality of VS Code allows me to quickly add arm-vn (VNet) and arm-avail (availability set) resources to the template.

The Virtual Network

I added a comma to the brace that marks the end of the storage account resource, and then the following code is automatically added when I added an arm-vn snippet:

The default new virtual network snippet [Image Credit: Aidan Finn]
The default new virtual network snippet [Image Credit: Aidan Finn]
I want to make a few changes. I will change the location setting so that it uses my RGLocation variable instead of running the resourceGroup() function again.

I am also going to convert the following settings into parameters with default values:

  • name: The desired name of the virtual network.
  • displayName: This will have the same value as name.
  • addressSpace\addressPrefixes: The network address of the new VNet.
  • subnets\name: The name of each of the 2 default subnets.
  • subnets\addressPrefix: The subnet address of each subnet, within the address space of the VNet.

I will have the following new parameters to customize the new network at the time of deployment:

The new JSON parameters for the virtual network [Image Credit: Aidan Finn]
The new JSON parameters for the virtual network [Image Credit: Aidan Finn]
And the new resource description that uses those parameters and the RGLocation variable will look as follows:

The customized VNet in the Azure JSON [Image Credit: Aidan Finn]
The customized VNet in the Azure JSON [Image Credit: Aidan Finn]

The Availability Set

I added a comma after the brace that ends the VNet definition and then typed arm-availability to add an availability set, as shown below.

The default Azure availability set JSON snippet [Image Credit: Aidan Finn]
The default Azure availability set JSON snippet [Image Credit: Aidan Finn]
I want to make two changes to this availability set:

  • name: Change this to a parameter.
  • displayName: Use the same value as name.
  • location: Use the RGLocation variable.

I will add a single parameter to the JSON file for the availability set:

The added variable for the ARM availability set JSON definition [Image Credit: Aidan Finn]
The added variable for the ARM availability set JSON definition [Image Credit: Aidan Finn]
The customized resource definition for the availability set is next:

The customized availability set in the Azure JSON [Image Credit: Aidan Finn]
The customized availability set in the Azure JSON [Image Credit: Aidan Finn]

The Complete JSON Template

Copying snippets from a website is a nightmare, so here is the complete JSON file:


You can deploy this template in several ways to quickly deploy a storage account, a virtual network (with two subnets), and an availability set with a minimal amount of effort, and you’ll get a consistent result every time.

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register