Part 4 – Arm Template – Use Variable

Create Variable:

We can use variable similar to parameters to add values to each resource properties. The difference between them is variable use function like “concatenation” to combine multiple variables or parameters.

Below examples shows the changes being added as variables into template which creates unique storage name.

 "$schema": "",
 "contentVersion": "",
 "parameters": {
   "storagePrefix": {
     "type": "string",
     "minLength": 3,
     "maxLength": 11
   "storageSKU": {
     "type": "string",
     "defaultValue": "Standard_LRS",
     "allowedValues": [
   "location": {
     "type": "string",
     "defaultValue": "[resourceGroup().location]"
 "variables": {
   "uniqueStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]"
 "resources": [
     "type": "Microsoft.Storage/storageAccounts",
     "apiVersion": "2019-04-01",
     "name": "[variables('uniqueStorageName')]",
     "location": "[parameters('location')]",
     "sku": {
       "name": "[parameters('storageSKU')]"
     "kind": "StorageV2",
     "properties": {
       "supportsHttpsTrafficOnly": true

uniqueStorageName: is a variable being created which uses four functions to  construct a string value.

uniqueString:  this function creates 13 character has value.

Concat: This functions construct or combine multiple parameter/variables together.

you can get more details about functions from this link:

Deploy template

New-AzResourceGroupDeployment `
  -Name addnamevariable `
  -ResourceGroupName myResourceGroup `
  -TemplateFile $templateFile `
  -storagePrefix "store" `
  -storageSKU Standard_LRS
Show More

Related Articles

Back to top button