Outputs in Azure Resource Manager template

This article describes how to define output values in your Azure Resource Manager template. You use outputs when you need to return values from the deployed resources.

Define output values

The following example shows how to return the resource ID for a public IP address:

"outputs": {
  "resourceID": {
    "type": "string",
    "value": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_name'))]"
  }
}

Conditional output

In the outputs section, you can conditionally return a value. Typically, you use condition in the outputs when you've conditionally deployed a resource. The following example shows how to conditionally return the resource ID for a public IP address based on whether a new one was deployed:

"outputs": {
  "resourceID": {
    "condition": "[equals(parameters('publicIpNewOrExisting'), 'new')]",
    "type": "string",
    "value": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_name'))]"
  }
}

For a simple example of conditional output, see conditional output template.

Linked templates

To retrieve the output value from a linked template, use the reference function in the parent template. The syntax in the parent template is:

"[reference('<deploymentName>').outputs.<propertyName>.value]"

When getting an output property from a linked template, the property name can't include a dash.

The following example shows how to set the IP address on a load balancer by retrieving a value from a linked template.

"publicIPAddress": {
  "id": "[reference('linkedTemplate').outputs.resourceID.value]"
}

You can't use the reference function in the outputs section of a nested template. To return the values for a deployed resource in a nested template, convert your nested template to a linked template.

Get output values

When the deployment succeeds, the output values are automatically returned in the results of the deployment.

To get output values from the deployment history, you can use script.

(Get-AzResourceGroupDeployment `
  -ResourceGroupName <resource-group-name> `
  -Name <deployment-name>).Outputs.resourceID.value

Example templates

The following examples demonstrate scenarios for using outputs.

Template Description
Copy variables Creates complex variables and outputs those values. Doesn't deploy any resources.
Public IP address Creates a public IP address and outputs the resource ID.
Load balancer Links to the preceding template. Uses the resource ID in the output when creating the load balancer.

Next steps