13

I am confused about where to use a variable and where to use a parameter in ARM templates. How do we make this call ?

The referenced script uses both. I am more curious of the justification of using variables.

enter image description here

Reference

Sample Service Fabric Azure Deploy Script

https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/service-fabric-oms/azuredeploy.json

Shui shengbao
  • 17,120
  • 2
  • 21
  • 40
Rıfat Erdem Sahin
  • 1,488
  • 20
  • 42

2 Answers2

13

In the Azure template json file:

parameters:Values that are provided when deployment is executed to customize resource deployment.

variables:Values that are used as JSON fragments in the template to simplify template language expressions.

More information please refer to this official document:Understand the structure and syntax of Azure Resource Manager templates.

I am more curious of the justification of using variables.

Based on my experience, if you only use the variable once, you don't need use variables. But if you want to use the variable multiple times, you had better use variables. Using variable can simplify your template to avoid duplication of content.

For example, if you don't use supportLogStorageAccountName more than once, you can just do:

"name": "[toLower(concat('sf', uniqueString(resourceGroup().id),'2'))]"

However if you use provide variable supportLogStorageAccountName several\many times, you can use variable to avoid duplication.

4c74356b41
  • 59,484
  • 5
  • 63
  • 109
Shui shengbao
  • 17,120
  • 2
  • 21
  • 40
  • Thanks, Shui! To add to the above answer for the **parameters** -- You can specify this in a separate file, thus customizing the same script for maybe Prod/Dev/Test environments. Example usage -- `New-AzResourceGroupDeployment -Name EgDeployment -ResourceGroupName EgRG -TemplateFile azuredeploy.json -TemplateParameterFile parameters.json`. Refer - [Parameters File](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-deploy#parameter-files) – sanchitkum Jun 08 '19 at 09:23
  • comparison to paramaters is missing – Blue Clouds Jan 28 '20 at 12:12
6

ARM templates are usually used to create a set of close to identical environments. The parameters are what differs them. This is commonly used for environment type (prod, dev, test) and performance/cost related parameters. Variables are used to create unique names for services based on or calculated from the parameters.

An example of this would the name of a storage account. This is usually done by concatenating a common name like _storage and an environment name parameter like “test” and store it in a variable. When you create another environment all you must do is change the environment type parameter.

Espen
  • 61
  • 3