Exercise - Add parameters and outputs to your Azure Resource Manager template
In this exercise, you add a parameter to define the Azure storage account name during deployment. Then, you add a parameter to define which storage-account SKUs are allowed, and define which one to use for this deployment. You also add usefulness to the Azure Resource Manager template (ARM template) by adding an output that you can use later in the deployment process.
Create parameters for the ARM template
Here, you make your ARM template more flexible by adding parameters that can be set at runtime. Create a parameter for the storageName value.
In the azuredeploy.json file in Visual Studio Code, update
"parameters":{},, so it looks like:"parameters": { "storageName": { "type": "string", "minLength": 3, "maxLength": 24, "metadata": { "description": "The name of the Azure storage resource" } } },To format the JSON file correctly, press Alt+Shift+F.
Use the new parameter in the
resourcesblock in both thenameanddisplayNamevalues. The entire file looks like this code example:{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "storageName": { "type": "string", "minLength": 3, "maxLength": 24, "metadata": { "description": "The name of the Azure storage resource" } } }, "functions": [], "variables": {}, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2025-01-01", "name": "[parameters('storageName')]", "tags": { "displayName": "[parameters('storageName')]" }, "location": "[resourceGroup().location]", "kind": "StorageV2", "sku": { "name": "Standard_LRS" } } ], "outputs": {} }Save the file.
Deploy the parameterized ARM template
Here, you change the name of the deployment to better reflect what this deployment does and fill in a value for the new parameter.
Run the following Azure CLI commands in the terminal. This script is identical to the one you used Previously, except the deployment name has been changed. Enter a unique value for the storageName parameter. It must be globally unique across Azure, contain 3 to 24 characters, and include only lowercase letters, numbers, and hyphens. You can reuse the unique name you created in the previous unit; if you do, Azure will update the existing resource instead of creating a new one.
templateFile="azuredeploy.json"
today=$(date +"%d-%b-%Y")
DeploymentName="addnameparameter-"$today
az deployment group create \
--name $DeploymentName \
--template-file $templateFile \
--parameters storageName={your-unique-name}
Run the following Azure PowerShell commands in the terminal. This script is identical to the one you used earlier, except the deployment name has been changed. Enter a unique value for the storageName parameter. It must be globally unique across Azure, contain 3 to 24 characters, and include only lowercase letters, numbers, and hyphens. You can reuse the unique name you created in the previous unit; if you do, Azure will update the existing resource instead of creating a new one.
$templateFile="azuredeploy.json"
$today=Get-Date -Format "MM-dd-yyyy"
$deploymentName="addnameparameter-"+"$today"
New-AzResourceGroupDeployment `
-Name $deploymentName `
-TemplateFile $templateFile `
-storageName {your-unique-name}
Check your deployment
When the deployment finishes, go back to the Azure portal in your browser. Go to your resource group, and see that there are now 3 Succeeded deployments. Select this link.
Notice that all three deployments are in the list.
Explore the addnameparameter deployment as you did previously.
Add another parameter that limits allowed values
Here, you use parameters to limit the values allowed for a parameter.
Add a new parameter named
storageSKUto theparameterssection of the azuredeploy.json file.// This is the allowed values for an Azure storage account "storageSKU": { "type": "string", "defaultValue": "Standard_LRS", "allowedValues": [ "Standard_LRS", "Standard_GRS", "Standard_RAGRS", "Standard_ZRS", "Premium_LRS", "Premium_ZRS", "Standard_GZRS", "Standard_RAGZRS" ] }The first line is a comment. ARM templates support
//and/* */comments.Update resources to use the
storageSKUparameter. If you take advantage of IntelliSense in Visual Studio Code, it makes this step easier."sku": { "name": "[parameters('storageSKU')]" }The entire file looks like this code example:
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "storageName": { "type": "string", "minLength": 3, "maxLength": 24, "metadata": { "description": "The name of the Azure storage resource" } }, "storageSKU": { "type": "string", "defaultValue": "Standard_LRS", "allowedValues": [ "Standard_LRS", "Standard_GRS", "Standard_RAGRS", "Standard_ZRS", "Premium_LRS", "Premium_ZRS", "Standard_GZRS", "Standard_RAGZRS" ] } }, "functions": [], "variables": {}, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2025-01-01", "name": "[parameters('storageName')]", "tags": { "displayName": "[parameters('storageName')]" }, "location": "[resourceGroup().location]", "kind": "StorageV2", "sku": { "name": "[parameters('storageSKU')]" } } ], "outputs": {} }Save the file.
Deploy the ARM template
Here, you deploy successfully by using a storageSKU parameter that's in the allowed list. Then, you try to deploy the template by using a storageSKU parameter that isn't in the allowed list. The second deployment fails as expected.
Deploy the template by running the following commands. Fill in a unique name for the
storageNameparameter. It must be globally unique across Azure, contain 3 to 24 characters, and include only lowercase letters, numbers, and hyphens. You can reuse the unique name you created in the previous unit; if you do, Azure will update the existing resource instead of creating a new one.templateFile="azuredeploy.json" today=$(date +"%d-%b-%Y") DeploymentName="addSkuParameter-"$today az deployment group create \ --name $DeploymentName \ --template-file $templateFile \ --parameters storageSKU=Standard_GRS storageName={your-unique-name}Allow this deployment to finish. This deployment succeeds as expected. Your list of allowed values, prevents your template's users from passing in parameter values that don't work for the resource. Let's see what happens when you provide an invalid SKU.
Run the following commands to deploy the template with a parameter that isn't allowed. Here, you changed the
storageSKUparameter to Basic. Fill in a unique name for thestorageNameparameter. It must be globally unique across Azure, contain 3 to 24 characters, and include only lowercase letters, numbers, and hyphens. You can reuse the unique name you created in the previous unit; if you do, Azure will update the existing resource instead of creating a new one.templateFile="azuredeploy.json" today=$(date +"%d-%b-%Y") DeploymentName="addSkuParameter-"$today az deployment group create \ --name $DeploymentName \ --template-file $templateFile \ --parameters storageSKU=Basic storageName={your-unique-name}This deployment fails. Notice the error.
Deploy the template by running the following commands. Fill in a unique name for the
storageNameparameter. It must be globally unique across Azure, contain 3 to 24 characters, and include only lowercase letters, numbers, and hyphens. You can reuse the unique name you created in the previous unit; if you do, Azure will update the existing resource instead of creating a new one.$today=Get-Date -Format "MM-dd-yyyy" $deploymentName="addSkuParameter-"+"$today" New-AzResourceGroupDeployment ` -Name $deploymentName ` -TemplateFile $templateFile ` -storageName {your-unique-name} ` -storageSKU Standard_GRSAllow this deployment to finish. This deployment succeeds as expected. Your list of allowed values, prevents your template's users from passing in parameter values that don't work for the resource. Let's see what happens when you provide an invalid SKU.
Run the following commands to deploy the template with a parameter that isn't allowed. Here, you changed the
storageSKUparameter to Basic. Fill in a unique name for thestorageNameparameter. It must be globally unique across Azure, contain 3 to 24 characters, and include only lowercase letters, numbers, and hyphens. You can reuse the unique name you created in the previous unit; if you do, Azure will update the existing resource instead of creating a new one.$today=Get-Date -Format "MM-dd-yyyy" $deploymentName="addSkuParameter-"+"$today" New-AzResourceGroupDeployment ` -Name $deploymentName ` -TemplateFile $templateFile ` -storageName {your-unique-name} ` -storageSKU BasicThis deployment fails. Notice the error.
Add output to the ARM template
Here, you add to the outputs section of the ARM template to output the endpoints for the storage account resource.
In the azuredeploy.json file in Visual Studio Code, update
"outputs":{},so it looks like:"outputs": { "storageEndpoint": { "type": "object", "value": "[reference(parameters('storageName')).primaryEndpoints]" } }Save the file.
Deploy the ARM template with an output
Here, you deploy the template and see the endpoints output as JSON. You need to fill in a unique name for the storageName parameter. It must be globally unique across Azure, contain 3 to 24 characters, and include only lowercase letters, numbers, and hyphens. You can reuse the unique name you created in the previous unit; if you do, Azure will update the existing resource instead of creating a new one.
Deploy the template by running the following commands. Be sure to replace {your-unique-name} with a string unique to you.
templateFile="azuredeploy.json" today=$(date +"%d-%b-%Y") DeploymentName="addoutputs-"$today az deployment group create \ --name $DeploymentName \ --template-file $templateFile \ --parameters storageSKU=Standard_LRS storageName={your-unique-name}Notice the output.
Deploy the template by running the following commands. Be sure to replace {your-unique-name} with a string unique to you.
$today=Get-Date -Format "MM-dd-yyyy" $deploymentName="addOutputs-"+"$today" New-AzResourceGroupDeployment ` -Name $deploymentName ` -TemplateFile $templateFile ` -storageName {your-unique-name} ` -storageSKU Standard_LRSNotice the output.
Check your output deployment
In the Azure portal, go to your addOutputs deployment. You can find your output there as well.