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 - logical | Microsoft Docs |
Describes the functions to use in an Azure Resource Manager template to determine logical values. |
azure-resource-manager |
na |
tfitzmac |
timlt |
tysonn |
azure-resource-manager |
na |
article |
na |
na |
09/05/2017 |
tomfitz |
Resource Manager provides several functions for making comparisons in your templates.
and(arg1, arg2)
Checks whether both parameter values are true.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | boolean | The first value to check whether is true. |
arg2 | Yes | boolean | The second value to check whether is true. |
Returns True if both values are true; otherwise, False.
The following example template shows how to use logical functions.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [ ],
"outputs": {
"andExampleOutput": {
"value": "[and(bool('true'), bool('false'))]",
"type": "bool"
},
"orExampleOutput": {
"value": "[or(bool('true'), bool('false'))]",
"type": "bool"
},
"notExampleOutput": {
"value": "[not(bool('true'))]",
"type": "bool"
}
}
}
The output from the preceding example is:
Name | Type | Value |
---|---|---|
andExampleOutput | Bool | False |
orExampleOutput | Bool | True |
notExampleOutput | Bool | False |
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/andornot.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/andornot.json
bool(arg1)
Converts the parameter to a boolean.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | string or int | The value to convert to a boolean. |
A boolean of the converted value.
The following example template shows how to use bool with a string or integer.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [],
"outputs": {
"trueString": {
"value": "[bool('true')]",
"type" : "bool"
},
"falseString": {
"value": "[bool('false')]",
"type" : "bool"
},
"trueInt": {
"value": "[bool(1)]",
"type" : "bool"
},
"falseInt": {
"value": "[bool(0)]",
"type" : "bool"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
trueString | Bool | True |
falseString | Bool | False |
trueInt | Bool | True |
falseInt | Bool | False |
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/bool.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/bool.json
if(condition, trueValue, falseValue)
Returns a value based on whether a condition is true or false.
Parameter | Required | Type | Description |
---|---|---|---|
condition | Yes | boolean | The value to check whether it is true. |
trueValue | Yes | string, int, object, or array | The value to return when the condition is true. |
falseValue | Yes | string, int, object, or array | The value to return when the condition is false. |
Returns second parameter when first parameter is True; otherwise, returns third parameter.
You can use this function to conditionally set a resource property. The following example is not a full template, but it shows the relevant portions for conditionally setting the availability set.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
...
"availabilitySet": {
"type": "string",
"allowedValues": [
"yes",
"no"
]
}
},
"variables": {
...
"availabilitySetName": "availabilitySet1",
"availabilitySet": {
"id": "[resourceId('Microsoft.Compute/availabilitySets',variables('availabilitySetName'))]"
}
},
"resources": [
{
"condition": "[equals(parameters('availabilitySet'),'yes')]",
"type": "Microsoft.Compute/availabilitySets",
"name": "[variables('availabilitySetName')]",
...
},
{
"apiVersion": "2016-03-30",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"availabilitySet": "[if(equals(parameters('availabilitySet'),'yes'), variables('availabilitySet'), json('null'))]",
...
}
},
...
],
...
}
The following example template shows how to use the if
function.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
],
"outputs": {
"yesOutput": {
"type": "string",
"value": "[if(equals('a', 'a'), 'yes', 'no')]"
},
"noOutput": {
"type": "string",
"value": "[if(equals('a', 'b'), 'yes', 'no')]"
}
}
}
The output from the preceding example is:
Name | Type | Value |
---|---|---|
yesOutput | String | yes |
noOutput | String | no |
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/if.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/if.json
not(arg1)
Converts boolean value to its opposite value.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | boolean | The value to convert. |
Returns True when parameter is False. Returns False when parameter is True.
The following example template shows how to use logical functions.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [ ],
"outputs": {
"andExampleOutput": {
"value": "[and(bool('true'), bool('false'))]",
"type": "bool"
},
"orExampleOutput": {
"value": "[or(bool('true'), bool('false'))]",
"type": "bool"
},
"notExampleOutput": {
"value": "[not(bool('true'))]",
"type": "bool"
}
}
}
The output from the preceding example is:
Name | Type | Value |
---|---|---|
andExampleOutput | Bool | False |
orExampleOutput | Bool | True |
notExampleOutput | Bool | False |
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/andornot.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/andornot.json
The following example template uses not with equals.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
],
"outputs": {
"checkNotEquals": {
"type": "bool",
"value": "[not(equals(1, 2))]"
}
}
The output from the preceding example is:
Name | Type | Value |
---|---|---|
checkNotEquals | Bool | True |
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/not-equals.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/not-equals.json
or(arg1, arg2)
Checks whether either parameter value is true.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | boolean | The first value to check whether is true. |
arg2 | Yes | boolean | The second value to check whether is true. |
Returns True if either value is true; otherwise, False.
The following example template shows how to use logical functions.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [ ],
"outputs": {
"andExampleOutput": {
"value": "[and(bool('true'), bool('false'))]",
"type": "bool"
},
"orExampleOutput": {
"value": "[or(bool('true'), bool('false'))]",
"type": "bool"
},
"notExampleOutput": {
"value": "[not(bool('true'))]",
"type": "bool"
}
}
}
The output from the preceding example is:
Name | Type | Value |
---|---|---|
andExampleOutput | Bool | False |
orExampleOutput | Bool | True |
notExampleOutput | Bool | False |
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/andornot.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/andornot.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.