title | description | services | documentationcenter | author | manager | editor | ms.assetid | ms.service | ms.devlang | ms.topic | ms.tgt_pltfrm | ms.workload | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Azure Resource Manager template functions - numeric | Microsoft Docs |
Describes the functions to use in an Azure Resource Manager template to work with numbers. |
azure-resource-manager |
na |
tfitzmac |
timlt |
tysonn |
azure-resource-manager |
na |
reference |
na |
na |
11/08/2017 |
tomfitz |
Resource Manager provides the following functions for working with integers:
add(operand1, operand2)
Returns the sum of the two provided integers.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | First number to add. |
operand2 | Yes | int | Second number to add. |
An integer that contains the sum of the parameters.
The following example template adds two parameters.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 5,
"metadata": {
"description": "First integer to add"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Second integer to add"
}
}
},
"resources": [
],
"outputs": {
"addResult": {
"type": "int",
"value": "[add(parameters('first'), parameters('second'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
addResult | Int | 8 |
To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/add.json
To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/add.json
copyIndex(loopName, offset)
Returns the index of an iteration loop.
Parameter | Required | Type | Description |
---|---|---|---|
loopName | No | string | The name of the loop for getting the iteration. |
offset | No | int | The number to add to the zero-based iteration value. |
This function is always used with a copy object. If no value is provided for offset, the current iteration value is returned. The iteration value starts at zero. You can use iteration loops when defining either resources or variables.
The loopName property enables you to specify whether copyIndex is referring to a resource iteration or property iteration. If no value is provided for loopName, the current resource type iteration is used. Provide a value for loopName when iterating on a property.
For a complete description of how you use copyIndex, see Create multiple instances of resources in Azure Resource Manager.
For an example of using copyIndex when defining a variable, see Variables.
The following example shows a copy loop and the index value included in the name.
"resources": [
{
"name": "[concat('examplecopy-', copyIndex())]",
"type": "Microsoft.Web/sites",
"copy": {
"name": "websitescopy",
"count": "[parameters('count')]"
},
...
}
]
An integer representing the current index of the iteration.
div(operand1, operand2)
Returns the integer division of the two provided integers.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | The number being divided. |
operand2 | Yes | int | The number that is used to divide. Cannot be 0. |
An integer representing the division.
The following example template divides one parameter by another parameter.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 8,
"metadata": {
"description": "Integer being divided"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Integer used to divide"
}
}
},
"resources": [
],
"outputs": {
"divResult": {
"type": "int",
"value": "[div(parameters('first'), parameters('second'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
divResult | Int | 2 |
To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/div.json
To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/div.json
float(arg1)
Converts the value to a floating point number. You only use this function when passing custom parameters to an application, such as a Logic App.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | string or int | The value to convert to a floating point number. |
A floating point number.
The following example shows how to use float to pass parameters to a Logic App:
{
"type": "Microsoft.Logic/workflows",
"properties": {
...
"parameters": {
"custom1": {
"value": "[float('3.0')]"
},
"custom2": {
"value": "[float(3)]"
},
int(valueToConvert)
Converts the specified value to an integer.
Parameter | Required | Type | Description |
---|---|---|---|
valueToConvert | Yes | string or int | The value to convert to an integer. |
An integer of the converted value.
The following example template converts the user-provided parameter value to integer.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"stringToConvert": {
"type": "string",
"defaultValue": "4"
}
},
"resources": [
],
"outputs": {
"intResult": {
"type": "int",
"value": "[int(parameters('stringToConvert'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
intResult | Int | 4 |
To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/int.json
To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/int.json
max (arg1)
Returns the maximum value from an array of integers or a comma-separated list of integers.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | array of integers, or comma-separated list of integers | The collection to get the maximum value. |
An integer representing the maximum value from the collection.
The following example template shows how to use max with an array and a list of integers:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"arrayToTest": {
"type": "array",
"defaultValue": [0,3,2,5,4]
}
},
"resources": [],
"outputs": {
"arrayOutput": {
"type": "int",
"value": "[max(parameters('arrayToTest'))]"
},
"intOutput": {
"type": "int",
"value": "[max(0,3,2,5,4)]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayOutput | Int | 5 |
intOutput | Int | 5 |
To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/max.json
To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/max.json
min (arg1)
Returns the minimum value from an array of integers or a comma-separated list of integers.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | array of integers, or comma-separated list of integers | The collection to get the minimum value. |
An integer representing minimum value from the collection.
The following example template shows how to use min with an array and a list of integers:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"arrayToTest": {
"type": "array",
"defaultValue": [0,3,2,5,4]
}
},
"resources": [],
"outputs": {
"arrayOutput": {
"type": "int",
"value": "[min(parameters('arrayToTest'))]"
},
"intOutput": {
"type": "int",
"value": "[min(0,3,2,5,4)]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayOutput | Int | 0 |
intOutput | Int | 0 |
To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/min.json
To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/min.json
mod(operand1, operand2)
Returns the remainder of the integer division using the two provided integers.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | The number being divided. |
operand2 | Yes | int | The number that is used to divide, Cannot be 0. |
An integer representing the remainder.
The following example template returns the remainder of dividing one parameter by another parameter.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 7,
"metadata": {
"description": "Integer being divided"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Integer used to divide"
}
}
},
"resources": [
],
"outputs": {
"modResult": {
"type": "int",
"value": "[mod(parameters('first'), parameters('second'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
modResult | Int | 1 |
To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/mod.json
To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/mod.json
mul(operand1, operand2)
Returns the multiplication of the two provided integers.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | First number to multiply. |
operand2 | Yes | int | Second number to multiply. |
An integer representing the multiplication.
The following example template multiplies one parameter by another parameter.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 5,
"metadata": {
"description": "First integer to multiply"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Second integer to multiply"
}
}
},
"resources": [
],
"outputs": {
"mulResult": {
"type": "int",
"value": "[mul(parameters('first'), parameters('second'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
mulResult | Int | 15 |
To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/mul.json
To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/mul.json
sub(operand1, operand2)
Returns the subtraction of the two provided integers.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | The number that is subtracted from. |
operand2 | Yes | int | The number that is subtracted. |
An integer representing the subtraction.
The following example template subtracts one parameter from another parameter.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 7,
"metadata": {
"description": "Integer subtracted from"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Integer to subtract"
}
}
},
"resources": [
],
"outputs": {
"subResult": {
"type": "int",
"value": "[sub(parameters('first'), parameters('second'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
subResult | Int | 4 |
To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/sub.json
To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/sub.json
- For a description of the sections in an Azure Resource Manager template, see Authoring Azure Resource Manager templates.
- To merge multiple templates, see Using linked templates with Azure Resource Manager.
- To iterate a specified number of times when creating a type of resource, see Create multiple instances of resources in Azure Resource Manager.
- To see how to deploy the template you have created, see Deploy an application with Azure Resource Manager template.