0
0
Azurecloud~5 mins

ARM template parameters and variables in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
When creating resources in Azure, you often need to customize settings without changing the whole template. Parameters and variables help you reuse templates by allowing input values and storing reusable data inside the template.
When you want to deploy the same infrastructure with different names or sizes without editing the template each time
When you need to keep some values fixed inside the template for reuse, like location or tags
When you want to make your template easier to read and maintain by separating input values from fixed values
When you want to share a template with others and let them provide their own settings
When you want to avoid repeating the same value multiple times inside the template
Config File - azuredeploy.json
azuredeploy.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountName": {
      "type": "string",
      "metadata": {
        "description": "Name of the storage account"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "eastus",
      "metadata": {
        "description": "Location for all resources"
      }
    }
  },
  "variables": {
    "storageAccountType": "Standard_LRS",
    "storageAccountId": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2022-09-01",
      "name": "[parameters('storageAccountName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[variables('storageAccountType')]"
      },
      "kind": "StorageV2",
      "properties": {}
    }
  ],
  "outputs": {
    "storageAccountResourceId": {
      "type": "string",
      "value": "[variables('storageAccountId')]"
    }
  }
}

parameters: Define inputs you provide when deploying, like storage account name and location.

variables: Store fixed or computed values used inside the template, like the storage account type and resource ID.

resources: Define the Azure resources to create, using parameters and variables for configuration.

outputs: Return useful information after deployment, here the resource ID of the storage account.

Commands
This command deploys the ARM template to the resource group 'example-rg' using the template file. It sets the storage account name parameter to 'examplestorage123'.
Terminal
az deployment group create --resource-group example-rg --template-file azuredeploy.json --parameters storageAccountName=examplestorage123
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Resources/deployments/deployment1", "name": "deployment1", "properties": { "provisioningState": "Succeeded", "outputs": { "storageAccountResourceId": { "type": "String", "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorage123" } } }, "type": "Microsoft.Resources/deployments" }
--resource-group - Specifies the Azure resource group to deploy to
--template-file - Specifies the ARM template file to use
--parameters - Sets the input parameters for the template
This command shows details about the deployment named 'deployment1' in the resource group 'example-rg' to verify the deployment status and outputs.
Terminal
az deployment group show --resource-group example-rg --name deployment1
Expected OutputExpected
{ "name": "deployment1", "properties": { "provisioningState": "Succeeded", "outputs": { "storageAccountResourceId": { "type": "String", "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorage123" } } } }
--resource-group - Specifies the resource group of the deployment
--name - Specifies the deployment name to query
Key Concept

If you remember nothing else from this pattern, remember: parameters let you customize your template inputs, and variables let you reuse fixed or computed values inside the template.

Common Mistakes
Not providing required parameters when deploying the template
The deployment fails because the template expects input values that are missing
Always provide values for all required parameters either via command line or a parameters file
Trying to use variables as parameters or vice versa
Parameters are inputs from outside, variables are internal; mixing them causes errors or unexpected behavior
Use parameters for inputs you want to change at deployment time, variables for fixed or computed values inside the template
Summary
Define parameters in the ARM template to accept input values at deployment time.
Use variables to store fixed or computed values for reuse inside the template.
Deploy the template with parameters using the Azure CLI and verify the deployment outputs.