You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Parameters, variables, and outputs make ARM templates flexible and reusable. Parameters accept input at deployment time, variables simplify repeated expressions, and outputs return values after deployment. In this lesson, you will learn how to use all three effectively.
Parameters allow you to provide values when deploying a template. This makes templates reusable across environments.
{
"parameters": {
"environment": {
"type": "string",
"allowedValues": ["dev", "staging", "prod"],
"defaultValue": "dev",
"metadata": {
"description": "The deployment environment"
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_B2s",
"metadata": {
"description": "Size of the virtual machine"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Administrator password for the VM"
}
},
"instanceCount": {
"type": "int",
"defaultValue": 2,
"minValue": 1,
"maxValue": 10,
"metadata": {
"description": "Number of VM instances"
}
},
"enableDiagnostics": {
"type": "bool",
"defaultValue": true
},
"tags": {
"type": "object",
"defaultValue": {
"project": "webapp",
"costCentre": "12345"
}
}
}
}
| Type | Description |
|---|---|
| string | Text value |
| securestring | Sensitive text (not logged or displayed) |
| int | Integer number |
| bool | true or false |
| object | JSON object |
| secureObject | Sensitive JSON object |
| array | JSON array |
| Constraint | Purpose |
|---|---|
| defaultValue | Value used when none is provided |
| allowedValues | Restricts input to a predefined list |
| minValue / maxValue | Numeric range limits |
| minLength / maxLength | String or array length limits |
Use the parameters() function to reference a parameter value:
"location": "[parameters('location')]",
"name": "[format('vm-{0}-{1}', parameters('environment'), parameters('vmSize'))]"
Instead of passing parameters on the command line, you can use a parameter file:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"value": "prod"
},
"vmSize": {
"value": "Standard_D4s_v3"
},
"instanceCount": {
"value": 4
},
"enableDiagnostics": {
"value": true
},
"tags": {
"value": {
"project": "webapp",
"costCentre": "12345",
"environment": "production"
}
}
}
}
Deploy with a parameter file:
az deployment group create \
--resource-group rg-webapp-prod \
--template-file main.json \
--parameters @parameters.prod.json
For secrets, reference Azure Key Vault directly:
{
"adminPassword": {
"reference": {
"keyVault": {
"id": "/subscriptions/<sub-id>/resourceGroups/<rg>/providers/Microsoft.KeyVault/vaults/<vault>"
},
"secretName": "vmAdminPassword"
}
}
}
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.