0
0
Azurecloud~5 mins

ARM template outputs in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you deploy resources in Azure using ARM templates, you often want to see important information about what was created. Outputs let you get this information easily after deployment, like IP addresses or resource IDs.
When you want to know the public IP address of a virtual machine after deployment.
When you need to pass resource IDs from one template to another in a deployment pipeline.
When you want to confirm the names or locations of resources created by your template.
When you want to display connection strings or URLs generated during deployment.
When you want to debug or verify that your template created resources with expected properties.
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",
      "defaultValue": "examplestorageacct",
      "metadata": {
        "description": "Name of the storage account"
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2022-09-01",
      "name": "[parameters('storageAccountName')]",
      "location": "eastus",
      "sku": {
        "name": "Standard_LRS"
      },
      "kind": "StorageV2",
      "properties": {}
    }
  ],
  "outputs": {
    "storageAccountId": {
      "type": "string",
      "value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
    },
    "storageAccountPrimaryLocation": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))).primaryLocation]"
    }
  }
}

This ARM template creates a storage account with a given name in the East US region.

The outputs section defines two outputs:

  • storageAccountId: The full resource ID of the storage account, useful for referencing it elsewhere.
  • storageAccountPrimaryLocation: The primary location of the storage account, retrieved from the resource's properties.

These outputs let you see key information after deployment.

Commands
This command deploys the ARM template to the resource group named 'example-rg' with the storage account name parameter set. It creates the storage account and outputs the deployment results including the outputs defined.
Terminal
az deployment group create --resource-group example-rg --template-file azuredeploy.json --parameters storageAccountName=examplestorageacct
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Resources/deployments/deployment1", "name": "deployment1", "properties": { "outputs": { "storageAccountId": { "type": "String", "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorageacct" }, "storageAccountPrimaryLocation": { "type": "String", "value": "eastus" } }, "provisioningState": "Succeeded" } }
--resource-group - Specifies the Azure resource group to deploy the template into
--template-file - Specifies the path to the ARM template JSON file
--parameters - Sets the parameters for the template deployment
This command retrieves and shows only the outputs from the deployment named 'deployment1' in the resource group. It helps you quickly see the output values without extra details.
Terminal
az deployment group show --resource-group example-rg --name deployment1 --query properties.outputs
Expected OutputExpected
{ "storageAccountId": { "type": "String", "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorageacct" }, "storageAccountPrimaryLocation": { "type": "String", "value": "eastus" } }
--query - Filters the output to show only the outputs section
Key Concept

If you remember nothing else from this pattern, remember: ARM template outputs let you get important information about deployed resources immediately after deployment.

Common Mistakes
Not defining outputs in the ARM template and expecting to see resource details after deployment.
Without outputs, the deployment command does not return specific resource information, making it hard to get useful data.
Always define outputs in your ARM template for any resource information you want to retrieve after deployment.
Using incorrect expressions in the outputs value, like missing resourceId or reference functions.
Incorrect expressions cause deployment errors or empty output values.
Use proper ARM template functions like resourceId() and reference() to get resource properties in outputs.
Not specifying the deployment name when querying outputs with az deployment group show.
Without the deployment name, the command cannot find the correct deployment outputs.
Always provide the deployment name with --name flag to retrieve outputs.
Summary
Define outputs in your ARM template to get useful information about deployed resources.
Use az deployment group create to deploy the template and see outputs in the deployment result.
Use az deployment group show with --query to retrieve outputs separately after deployment.