Deployment functions for Azure Resource Manager templates

Resource Manager provides the following functions for getting values related to the current deployment:

To get values from resources, resource groups, or subscriptions, see Resource functions.

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 the deployment object is passed as a link or as an in-line object. When the deployment object is passed in-line, such as when using the -TemplateFile parameter in Azure PowerShell to point to a local file, the returned object has the following format:

{
    "name": "",
    "properties": {
        "template": {
            "$schema": "",
            "contentVersion": "",
            "parameters": {},
            "variables": {},
            "resources": [
            ],
            "outputs": {}
        },
        "parameters": {},
        "mode": "",
        "provisioningState": ""
    }
}

When the object is passed as a link, such as when using the -TemplateUri parameter to point to a remote object, the object is returned in the following format:

{
    "name": "",
    "properties": {
        "templateLink": {
            "uri": ""
        },
        "template": {
            "$schema": "",
            "contentVersion": "",
            "parameters": {},
            "variables": {},
            "resources": [],
            "outputs": {}
        },
        "parameters": {},
        "mode": "",
        "provisioningState": ""
    }
}

When you deploy to an Azure subscription, instead of a resource group, the return object includes a location property. The location property is included when deploying either a local template or an external template.

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/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [],
    "outputs": {
        "subscriptionOutput": {
            "value": "[deployment()]",
            "type" : "object"
        }
    }
}

The preceding example returns the following object:

{
  "name": "deployment",
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [],
      "outputs": {
        "subscriptionOutput": {
          "type": "Object",
          "value": "[deployment()]"
        }
      }
    },
    "parameters": {},
    "mode": "Incremental",
    "provisioningState": "Accepted"
  }
}

For a subscription-level template that uses the deployment function, see subscription deployment function. It's deployed with either az deployment create or New-AzDeployment commands.

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": {
            "value": "[environment()]",
            "type" : "object"
        }
    }
}

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": [
   {
      "apiVersion": "2016-08-01",
      "name": "[parameters('siteName')]",
      "type": "Microsoft.Web/Sites",
      ...
   }
]

Example

The following example template shows a simplified use of the parameters function.

{
	"$schema": "https://schema.management.azure.com/schemas/2015-01-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 Azure Resource Manager template.

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/2015-01-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 Azure Resource Manager template.

Next steps