Using objects as parameter input for your ARM template deployment

1 minute read

I often try to make my deployments as dynamically as possible but for some resources this is not possible at all. Think about a VNET with multiple subnets and possibly a NSG. I try to overcome this by providing these not-so-dynamically-created values by using an object as parameter.

In this blog I will learn you how to deploy a use an object type parameter for your VNET and Subnet deployment. Before you start take a look at the pre-requisites.

  • Azure Subscription with at least contributor rights
  • I assume that you have some experience with ARM templates and know how to deploy them

First we need to create the ARM template. I have one on my Github which is ready for use (along with the parameter file below). This template can be used for deploying 1 vnet with multiple subnets.

In the following picture I will explain the details of the ARM template:

</figure>

  1. This is the parameter we are going to fill with the needed information. Important is the “type” is set to “object”.
  2. In this part we select the parameter values by using the . (dot) operator.
  3. Because we want to create multiple subnets we are using a copy statement to iterate over the values in the supplied object parameter, again by using the . (dot) operator
  4. This outputs the name of the deployed VNET.

Below is a snippet of the object we can provide as a parameter to the template: “parameters”:{ “VNetSettings”:{ “value”:{ {} }

If you look closely in the example below you’ll notice that the values for “Address Prefixes” and “Subnets” are provided as an array. (between the brackets [])

Now edit the parameter file to your liking and try to deploy the template via your preferred deployment tool. In this example I use Powershell with the New-AzResourceGroupDeployment cmdlet.

$Location = “West Europe”
$ResourceGroupName = “Network”

New-AzResourceGroup -ResourceGroupName $ResourceGroupName -Location $Location

New-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile .\networking\vnet.json -TemplateParameterFile .\networking\vnet.parameters.json

Now you’ve learned how to use an object as a parameter. I find this very easy and convenient to use throughout my deployments for several resources. Thank you for reading and stay safe!

Comments