Deployment functions for ARM templates
Resource Manager provides the following functions for getting values related to the current deployment of your Azure Resource Manager template (ARM template):
To get values from resources, resource groups, or subscriptions, see Resource functions.
Note
This article contains Bicep examples. Bicep is currently in preview. For more information, see Project Bicep.
deployment
deployment()
Returns information about the current deployment operation.
Return value
This function returns the object that is passed during deployment. The properties in the returned object differ based on whether you are:
- deploying a template that is a local file or deploying a template that is a remote file accessed through a URI.
- deploying to a resource group or deploying to one of the other scopes (Azure subscription, management group, or tenant).
When deploying a local template to a resource group: the function returns the following format:
{
"name": "",
"properties": {
"template": {
"$schema": "",
"contentVersion": "",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {}
},
"templateHash": "",
"parameters": {},
"mode": "",
"provisioningState": ""
}
}
When deploying a remote template to a resource group: the function returns the following format:
{
"name": "",
"properties": {
"templateLink": {
"uri": ""
},
"template": {
"$schema": "",
"contentVersion": "",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {}
},
"templateHash": "",
"parameters": {},
"mode": "",
"provisioningState": ""
}
}
When you deploy to an Azure subscription, management group, or tenant, the return object includes a location
property. The location property is included when deploying either a local template or an external template. The format is:
{
"name": "",
"location": "",
"properties": {
"template": {
"$schema": "",
"contentVersion": "",
"resources": [],
"outputs": {}
},
"templateHash": "",
"parameters": {},
"mode": "",
"provisioningState": ""
}
}
Remarks
You can use deployment() to link to another template based on the URI of the parent template.
"variables": {
"sharedTemplateUrl": "[uri(deployment().properties.templateLink.uri, 'shared-resources.json')]"
}
If you redeploy a template from the deployment history in the portal, the template is deployed as a local file. The templateLink
property isn't returned in the deployment function. If your template relies on templateLink
to construct a link to another template, don't use the portal to redeploy. Instead, use the commands you used to originally deploy the template.
Example
The following example template returns the deployment object:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [],
"outputs": {
"deploymentOutput": {
"type": "object",
"value": "[deployment()]"
}
}
}
The preceding example returns the following object:
{
"name": "deployment",
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [],
"outputs": {
"deploymentOutput": {
"type": "Object",
"value": "[deployment()]"
}
}
},
"templateHash": "13135986259522608210",
"parameters": {},
"mode": "Incremental",
"provisioningState": "Accepted"
}
}
environment
environment()
Returns information about the Azure environment used for deployment.
Return value
This function returns properties for the current Azure environment. The following example shows the properties for global Azure. Sovereign clouds may return slightly different properties.
{
"name": "",
"gallery": "",
"graph": "",
"portal": "",
"graphAudience": "",
"activeDirectoryDataLake": "",
"batch": "",
"media": "",
"sqlManagement": "",
"vmImageAliasDoc": "",
"resourceManager": "",
"authentication": {
"loginEndpoint": "",
"audiences": [
"",
""
],
"tenant": "",
"identityProvider": ""
},
"suffixes": {
"acrLoginServer": "",
"azureDatalakeAnalyticsCatalogAndJob": "",
"azureDatalakeStoreFileSystem": "",
"azureFrontDoorEndpointSuffix": "",
"keyvaultDns": "",
"sqlServerHostname": "",
"storage": ""
}
}
Example
The following example template returns the environment object.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [],
"outputs": {
"environmentOutput": {
"type": "object",
"value": "[environment()]"
}
}
}
The preceding example returns the following object when deployed to global Azure:
{
"name": "AzureCloud",
"gallery": "https://gallery.azure.com/",
"graph": "https://graph.windows.net/",
"portal": "https://portal.azure.com",
"graphAudience": "https://graph.windows.net/",
"activeDirectoryDataLake": "https://datalake.azure.net/",
"batch": "https://batch.core.windows.net/",
"media": "https://rest.media.azure.net",
"sqlManagement": "https://management.core.windows.net:8443/",
"vmImageAliasDoc": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json",
"resourceManager": "https://management.azure.com/",
"authentication": {
"loginEndpoint": "https://login.windows.net/",
"audiences": [
"https://management.core.windows.net/",
"https://management.azure.com/"
],
"tenant": "common",
"identityProvider": "AAD"
},
"suffixes": {
"acrLoginServer": ".azurecr.io",
"azureDatalakeAnalyticsCatalogAndJob": "azuredatalakeanalytics.net",
"azureDatalakeStoreFileSystem": "azuredatalakestore.net",
"azureFrontDoorEndpointSuffix": "azurefd.net",
"keyvaultDns": ".vault.azure.net",
"sqlServerHostname": ".database.windows.net",
"storage": "core.windows.net"
}
}
parameters
parameters(parameterName)
Returns a parameter value. The specified parameter name must be defined in the parameters section of the template.
Parameters
Parameter | Required | Type | Description |
---|---|---|---|
parameterName | Yes | string | The name of the parameter to return. |
Return value
The value of the specified parameter.
Remarks
Typically, you use parameters to set resource values. The following example sets the name of web site to the parameter value passed in during deployment.
"parameters": {
"siteName": {
"type": "string"
}
}, "resources": [
{
"type": "Microsoft.Web/Sites",
"apiVersion": "2016-08-01",
"name": "[parameters('siteName')]",
...
}
]
Example
The following example template shows a simplified use of the parameters function.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"stringParameter": {
"type": "string",
"defaultValue": "option 1"
},
"intParameter": {
"type": "int",
"defaultValue": 1
},
"objectParameter": {
"type": "object",
"defaultValue": {
"one": "a",
"two": "b"
}
},
"arrayParameter": {
"type": "array",
"defaultValue": [ 1, 2, 3 ]
},
"crossParameter": {
"type": "string",
"defaultValue": "[parameters('stringParameter')]"
}
},
"variables": {},
"resources": [],
"outputs": {
"stringOutput": {
"value": "[parameters('stringParameter')]",
"type": "string"
},
"intOutput": {
"value": "[parameters('intParameter')]",
"type": "int"
},
"objectOutput": {
"value": "[parameters('objectParameter')]",
"type": "object"
},
"arrayOutput": {
"value": "[parameters('arrayParameter')]",
"type": "array"
},
"crossOutput": {
"value": "[parameters('crossParameter')]",
"type": "string"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
stringOutput | String | option 1 |
intOutput | Int | 1 |
objectOutput | Object | {"one": "a", "two": "b"} |
arrayOutput | Array | [1, 2, 3] |
crossOutput | String | option 1 |
For more information about using parameters, see Parameters in ARM templates.
variables
variables(variableName)
Returns the value of variable. The specified variable name must be defined in the variables section of the template.
Parameters
Parameter | Required | Type | Description |
---|---|---|---|
variableName | Yes | String | The name of the variable to return. |
Return value
The value of the specified variable.
Remarks
Typically, you use variables to simplify your template by constructing complex values only once. The following example constructs a unique name for a storage account.
"variables": {
"storageName": "[concat('storage', uniqueString(resourceGroup().id))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageName')]",
...
},
{
"type": "Microsoft.Compute/virtualMachines",
"dependsOn": [
"[variables('storageName')]"
],
...
}
],
Example
The following example template returns different variable values.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {
"var1": "myVariable",
"var2": [ 1, 2, 3, 4 ],
"var3": "[ variables('var1') ]",
"var4": {
"property1": "value1",
"property2": "value2"
}
},
"resources": [],
"outputs": {
"exampleOutput1": {
"value": "[variables('var1')]",
"type": "string"
},
"exampleOutput2": {
"value": "[variables('var2')]",
"type": "array"
},
"exampleOutput3": {
"value": "[variables('var3')]",
"type": "string"
},
"exampleOutput4": {
"value": "[variables('var4')]",
"type": "object"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
exampleOutput1 | String | myVariable |
exampleOutput2 | Array | [1, 2, 3, 4] |
exampleOutput3 | String | myVariable |
exampleOutput4 | Object | {"property1": "value1", "property2": "value2"} |
For more information about using variables, see Variables in ARM template.
Next steps
- For a description of the sections in an ARM template, see Understand the structure and syntax of ARM templates.