You are on page 1of 3

1/20/22, 11:17 PM Azure Resource Manager Parameters – Direct DevOps from Quality Thought

MENU

JANUARY 24, 2019

Azure Resource Manager Parameters

Using Parameters in ARM Templates


What is Parameter
In ARM Template parameter is the value that is provider which cannot be computed or worked out by azure
(eg names of resources)

Basic Parameter Syntax

"parameters": {

"<parameter-name>" : {

"type" : "<type-of-parameter-value>",

"defaultValue": "<default-value-of-parameter>",

"allowedValues": [ "<array-of-allowed-values>" ],

"minValue": <minimum-value-for-int>,

"maxValue": <maximum-value-for-int>,

"minLength": <minimum-length-for-string-or-array>,

"maxLength": <maximum-length-for-string-or-array-parameters>,

"metadata": {

"description": "<description-of-the parameter>"

Using Parameters
To use the Parameters we would use the same example referred in creating basic arm template
which is here
To Start with we have the following structure of arm template

"$schema": "https://schema.management.azure.com/schemas/2015-01-
01/deploymentTemplate.json#",

"contentVersion": "1.0.0.0",

"resources": [{

"name": "myVirtualNetwork",

"type": "Microsoft.Network/virtualNetworks",

"apiVersion": "2018-08-01",

"location": "East US",

"tags": {

"From": "ARM Template",

"Reason" : "Learning"

},

"properties":{

"addressSpace": {

"addressPrefixes":[ "10.1.0.0/16"]

},

In the above mentioned examples i would like to parametrize the names


1. virtual network name
2. subnet name

From the syntax section if i have to write the basic structure for virtual network name. It would be
like "networkName":{
"type": "string",
"defaultValue": "myVirtualNetwork",
"metadata": {
"description": "virtual networks name"
}
}
similarly the subnet name can be written as "subnetName":{
"type": "string",
"defaultValue": "myVirtualSubnet",
"metadata": {
"description": "Subnet's name"
}
}
add the above two steps snippets to your template

"$schema": "https://schema.management.azure.com/schemas/2015-01-
01/deploymentTemplate.json#",

"contentVersion": "1.0.0.0",

"parameters": {

"networkName":{

"type": "string",

"defaultValue": "myVirtualNetwork",

"metadata": {

"description": "virtual networks name"

},

"subnetName":{

https://directdevops.blog/2019/01/24/azure-resource-manager-parameters/ 1/3
1/20/22, 11:17 PM Azure Resource Manager Parameters – Direct DevOps from Quality Thought
"type": "string",

"defaultValue": "myVirtualSubnet",

"metadata": {

"description": "Subnet's name"

Now in the resources section we need to remove the hardcoded names of network & subnet with
parameters. For that we need to use specific function called parameters as describe over here script
would look as

"$schema": "https://schema.management.azure.com/schemas/2015-01-
01/deploymentTemplate.json#",

"contentVersion": "1.0.0.0",

"parameters": {

"networkName":{

"type": "string",

"defaultValue": "myVirtualNetwork",

"metadata": {

"description": "virtual networks name"

},

"subnetName":{

"type": "string",

"defaultValue": "myVirtualSubnet",

"metadata": {

"description": "Subnet's name"

In the same manner i would like to parametrize the address space array for the network & address
space string for subnet. The script will be change to as shown below

"$schema": "https://schema.management.azure.com/schemas/2015-01-
01/deploymentTemplate.json#",

"contentVersion": "1.0.0.0",

"parameters": {

"networkName":{

"type": "string",

"defaultValue": "myVirtualNetwork",

"metadata": {

"description": "virtual networks name"

},

"subnetName":{

"type": "string",

"defaultValue": "myVirtualSubnet",

"metadata": {

"description": "Subnet's name"

Lets execute this deployment. I would be using CLI to create this deployment. Refer here

az group create --name "testing" --location "East US"

az group deployment create --resource-group testing --template-file .\myfirstarm.json


--name myfirstparameterdeployment

Since we have added parameters, lets change the values of parameters during deployment
execution
Lets create a file which consists of all the values of parameters to be passed. I have decided to pass
the following

Name: myNewNetwork. (type = string)

Address space: 192.168.0.0/16. (type = array)

Subnet - Name : myNewSubnet. (type = string)

Subnet - Address range: 192.168.0.0/24. (type = string )

For this i would build a json file containing all of my parameters. I would need to consider types as
well Basic structure of the parameters file is

"$schema": "https://schema.management.azure.com/schemas/2015-01-
01/deploymentParameters.json#",

"contentVersion": "1.0.0.0",

"parameters": {

"<parameter-name>": {

"value": <parameter-value>

If we would create parameters file with name parameters.json for our purpose it would look like

"$schema": "https://schema.management.azure.com/schemas/2015-01-
01/deploymentParameters.json#",

"contentVersion": "1.0.0.0",

"parameters": {

"networkName": {

"value": "myNewNetwork"

},

"subnetName": {

"value":"myNewSubnet"

},

"networkAddressSpaces": {

"value":["192.168.0.0/16"]

},

https://directdevops.blog/2019/01/24/azure-resource-manager-parameters/ 2/3
1/20/22, 11:17 PM Azure Resource Manager Parameters – Direct DevOps from Quality Thought
"subnetAddressSpace": {

"value":"192.168.0.0/24"

Lets execute this deployment with parameters file . I would be using CLI to create this deployment. Refer here

az group create --name "testing" --location "East US"

az group deployment create --resource-group testing --template-file .\myfirstarm.json


--name myfirstparameterdeployment --parameters "@parameters.json"

One thought on “Azure Resource Manager Parameters”

azyp99 says:
January 25, 2019 at 7:20 pm

Very use full stuff for beginners !!

Loading...

Reply

Leave a Reply

Enter your comment here...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner


devops & cloud enthusiastic learner

VIEW ALL POSTS

 PREVIOUS POST

Azure Resource Manager

NEXT POST

Terraform Backends

POWERED BY WORDPRESS.COM.

https://directdevops.blog/2019/01/24/azure-resource-manager-parameters/ 3/3

You might also like