title | description | ms.topic | ms.custom | ms.date |
---|---|---|---|---|
Outputs in templates |
Describes how to define output values in an Azure Resource Manager template (ARM template). |
conceptual |
devx-track-arm-template |
03/20/2024 |
This article describes how to define output values in your Azure Resource Manager template (ARM template). You use outputs when you need to return values from the deployed resources.
The format of each output value must resolve to one of the data types.
Tip
We recommend Bicep because it offers the same capabilities as ARM templates and the syntax is easier to use. To learn more, see outputs.
You are limited to 64 outputs in a template. For more information, see Template limits.
The following example shows how to return a property from a deployed resource.
Add the outputs
section to the template. The output value gets the fully qualified domain name for a public IP address.
"outputs": {
"hostname": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))).dnsSettings.fqdn]"
},
}
If you need to output a property that has a hyphen in the name, use brackets around the name instead of dot notation. For example, use ['property-name']
instead of .property-name
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
"user": {
"user-name": "Test Person"
}
},
"resources": [
],
"outputs": {
"nameResult": {
"type": "string",
"value": "[variables('user')['user-name']]"
}
}
}
You can use the condition
element to conditionally return a value. Typically, you use a conditional output 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.
In some scenarios, you don't know the number of instances of a value you need to return when creating the template. You can return a variable number of values by using iterative output. Add the copy
element to iterate an output.
"outputs": {
"storageEndpoints": {
"type": "array",
"copy": {
"count": "[parameters('storageCount')]",
"input": "[reference(concat(copyIndex(), variables('baseName'))).primaryEndpoints.blob]"
}
}
}
For more information, see Output iteration in ARM templates.
You can deploy related templates by using 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]"
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]"
}
If the property name has a hyphen, use brackets around the name instead of dot notation.
"publicIPAddress": {
"id": "[reference('linkedTemplate').outputs['resource-ID'].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.
The Public IP address template creates a public IP address and outputs the resource ID. The Load balancer template links to the preceding template. It uses the resource ID in the output when creating the load balancer.
The following template doesn't deploy any resources. It shows some ways of returning outputs of different types.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/outputs.json":::
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
az deployment group show \
-g <resource-group-name> \
-n <deployment-name> \
--query properties.outputs.resourceID.value
[!INCLUDE JSON object ordering]
- To learn about the available properties for outputs, see Understand the structure and syntax of ARM templates.