You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Describes how to define variables in an Azure Resource Manager template (ARM template).
3
+
description: Describes how to define variables in an Azure Resource Manager template (ARM template) and Bicep file.
4
4
ms.topic: conceptual
5
-
ms.date: 01/26/2021
5
+
ms.date: 02/12/2021
6
6
---
7
7
8
-
# Variables in ARM template
8
+
# Variables in ARM templates
9
9
10
-
This article describes how to define and use variables in your Azure Resource Manager template (ARM template). You use variables to simplify your template. Rather than repeating complicated expressions throughout your template, you define a variable that contains the complicated expression. Then, you reference that variable as needed throughout your template.
10
+
This article describes how to define and use variables in your Azure Resource Manager template (ARM template) or Bicep file. You use variables to simplify your template. Rather than repeating complicated expressions throughout your template, you define a variable that contains the complicated expression. Then, you use that variable as needed throughout your template.
11
11
12
12
Resource Manager resolves variables before starting the deployment operations. Wherever the variable is used in the template, Resource Manager replaces it with the resolved value.
When defining a variable, provide a value or template expression that resolves to a [data type](template-syntax.md#data-types). You can use the value from a parameter or another variable when constructing the variable.
18
+
When defining a variable, you don't specify a [data type](template-syntax.md#data-types) for the variable. Instead provide a value or template expression. The variable type is inferred from the resolved value. The following example sets a variable to a string.
19
+
20
+
# [JSON](#tab/json)
21
+
22
+
```json
23
+
"variables": {
24
+
"stringVar": "example value"
25
+
},
26
+
```
27
+
28
+
# [Bicep](#tab/bicep)
29
+
30
+
```bicep
31
+
var stringVar = 'example value'
32
+
```
17
33
18
-
You can use [template functions](template-functions.md) in the variable declaration, but you can't use the [reference](template-functions-resource.md#reference) function or any of the [list](template-functions-resource.md#list) functions. These functions get the runtime state of a resource, and can't be executed before deployment when variables are resolved.
34
+
---
19
35
20
-
The following example shows a variable definition. It creates a string value for a storage account name. It uses several template functions to get a parameter value, and concatenates it to a unique string.
36
+
You can use the value from a parameter or another variable when constructing the variable.
You can use [template functions](template-functions.md) to construct the variable value.
67
+
68
+
In JSON templates, you can't use the [reference](template-functions-resource.md#reference) function or any of the [list](template-functions-resource.md#list) functions in the variable declaration. These functions get the runtime state of a resource, and can't be executed before deployment when variables are resolved.
69
+
70
+
The reference and list functions are valid when declaring a variable in a Bicep file.
71
+
72
+
The following example creates a string value for a storage account name. It uses several template functions to get a parameter value, and concatenates it to a unique string.
var storageName = '${toLower(storageNamePrefix)}${uniqueString(resourceGroup().id)}'
86
+
```
87
+
88
+
---
89
+
28
90
## Use variable
29
91
30
-
In the template, you reference the value for the parameter by using the [variables](template-functions-deployment.md#variables) function. The following example shows how to use the variable for a resource property.
92
+
The following example shows how to use the variable for a resource property.
93
+
94
+
# [JSON](#tab/json)
95
+
96
+
In a JSON template, you reference the value for the variable by using the [variables](template-functions-deployment.md#variables) function.
31
97
32
98
```json
33
99
"resources": [
@@ -39,18 +105,47 @@ In the template, you reference the value for the parameter by using the [variabl
39
105
]
40
106
```
41
107
108
+
# [Bicep](#tab/bicep)
109
+
110
+
In a Bicep file, you reference the value for the variable by providing the variable name.
You can define variables that hold related values for configuring an environment. You define the variable as an object with the values. The following example shows an object that holds values for two environments - **test** and **prod**. You pass in one of these values during deployment.
137
+
You can define variables that hold related values for configuring an environment. You define the variable as an object with the values. The following example shows an object that holds values for two environments - **test** and **prod**. Pass in one of these values during deployment.
0 commit comments