Deploying a JSON Template in Azure Using a Parameters File

Posted on January 20, 2017 by Aidan Finn in Cloud Computing with

This “how to” post will show you how to deploy a JSON template in Azure using PowerShell and a parameters JSON file.

The JSON template that I will use has been built up using a series of previously published posts:

 

 

The Parameters

The JSON template that was built in the above posts, MultipleResources.JSON, includes several parameters that are used to customize the deployment of:

  • A storage (Standard Storage) account
  • A VNet with 2 subnets
  • An availability set

Some of these parameters require completion and some include default values that you might want to override:

  • Storage Account Name: The default value is null (empty) and is used to provide a unique name to the new storage account.
  • Storage Account Resiliency: You can choose between LRS (Standard_LRS) and GRS (Standard_GRS). The default is LRS (Standard_LRS).
  • Network Name: The name of the new VNet, which has a default of nw-petri.
  • Network Address: The IPv4 address scope of the new VNet, which is set to 10.0.0.0/16 by default.
  • Subnet-1 Name: The name of the first subnet, which is sn-petri-01 by default.
  • Subnet-1 Address: By default, the address scope of the first subnet is 10.0.0.0/24.
  • Subnet-2 Name: The name of the second subnet, which is sn-petri-01 by default.
  • Subnet-2 Address: By default, the address scope of the second subnet is 10.0.0.0/24.
  • Availability Set Name: The name of the new availability set, which is as-petri-01 by default.
Sponsored

Create a Parameters JSON File

We will use the New-AzureRmResourceGroupDeployment cmdlet to send the JSON file to Azure and start the deployment. There are two ways that we can manipulate the parameters of the JSON using this cmdlet:

  • Use a JSON parameters file, which we will cover in this post.
  • Use the names of the JSON parameters as parameters to the cmdlet, which can be a bit unwieldy for even a small JSON template. We will not cover this approach in this post.

I’m going to use a JSON parameter file, which I’ve shared below, to customize the deployment of the JSON template. I created this file by copying the parameters section from the JSON template that we want to deploy into a new JSON file in VS Code. Each parameter has a single setting, called value. I simply renamed the original defaultValue setting to value, edited the parameter value that was being passed to override the default settings, and deleted the other unnecessary settings from each parameter.

The above parameters file was saved as Parameters.JSON, which must not be larger than 64KB.

Deploy JSON Using PowerShell

All deployments of a JSON template are done to a resource group; this can be an existing or a new resource group. If you are using a new resource group, then you must create that resource group. But before we do that, we need to sign into Azure and select the correct subscription.

We are working with ARM, so we’ll be using the ARM PowerShell cmdlets, identifiable by the “RM” in the noun part of the cmdlets. We will log into Azure as follows:

A window will appear; sign into this window with your assigned credentials for the desired Azure subscription. Then we will retrieve the list of subscriptions that this account has access to:

Copy the SubscriptionID of the desired subscription and use it in the below cmdlet to select the subscription:

Now we can create a resource group if a new one is required, and store details of the resource group in a variable called $rg:

Alternatively, if we are deploying the template to an existing resource group, we can store the details of that resource group in a variable called $rg:

Now I can execute the deployment and use the parameters JSON file to configure the deployment:

Sponsored

Note that the deployment is given a name; this is because you can do multiple deployments into a resource group using the same JSON template or a combination of JSON templates, and you’ll need the ability to track your deployments.

Deploying an Azure JSON template using a parameters file [Image Credit: Aidan Finn]

Deploying an Azure JSON template using a parameters file [Image Credit: Aidan Finn]

A minute or so later, the storage account, the virtual network (with subnets), and the availability set are deployed, as specified using the template JSON file and the settings included in the parameters JSON file.

Sponsored

Tagged with , , , , , , , , ,