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
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/variables.md
+9-33Lines changed: 9 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ A variable can't have the same name as a parameter, module, or resource. You can
18
18
19
19
### Untyped variables
20
20
21
-
When you define a variable without specifying a data type, the type is inferred from the value. The syntax for defining a untyped variable is:
21
+
When you define a variable without specifying a data type, the type is inferred from the value. The syntax for defining an untyped variable is:
22
22
23
23
```bicep
24
24
@<decorator>(<argument>)
@@ -68,7 +68,7 @@ var storageName = '${toLower(storageNamePrefix)}${uniqueString(resourceGroup().i
68
68
output uniqueStorageName string = storageName
69
69
```
70
70
71
-
The preceding example returns a value like the following:
71
+
The preceding example returns a value like the following output:
72
72
73
73
```json
74
74
"uniqueStorageName": {
@@ -79,7 +79,7 @@ The preceding example returns a value like the following:
79
79
80
80
### Typed variables
81
81
82
-
Bicep supports **typed variables**, where you explicitly declare the data type of a variable to ensure type safety and improve code clarity. The Benefits of typed variables:
82
+
Bicep supports **typed variables**, where you explicitly declare the data type of a variable to ensure type safety and improve code clarity. The benefits of typed variables:
83
83
84
84
-**Error detection**: The Bicep compiler validates that assigned values match the declared type, catching errors early.
85
85
-**Code clarity**: Explicit types make it clear what kind of data a variable holds.
@@ -106,22 +106,22 @@ var subnets: array = ['subnet1', 'subnet2']
106
106
Bicep supports the following types for variables:
107
107
108
108
-**Primitive types**:
109
-
-`string`: Text values (e.g., `'hello'`)
110
-
-`int`: Integer values (e.g., `42`)
109
+
-`string`: Text values (for example, `'hello'`)
110
+
-`int`: Integer values (for example, `42`)
111
111
-`bool`: Boolean values (`true` or `false`)
112
112
-**Complex types**:
113
-
-`array`: A list of values (e.g., `[1, 2, 3]`)
114
-
-`object`: A key-value collection (e.g., `{ key: 'value' }`)
113
+
-`array`: A list of values (for example, `[1, 2, 3]`)
114
+
-`object`: A key-value collection (for example, `{ key: 'value' }`)
115
115
-**Union types** (Bicep 0.4 or later):
116
-
- Allows a variable to accept multiple types (e.g., `string | int`).
116
+
- Allows a variable to accept multiple types (for example, `string | int`).
117
117
- Example:
118
118
119
119
```bicep
120
120
var flexibleId: string | int = 'resource123'
121
121
```
122
122
123
123
- **Literal types**:
124
-
- Restrict a variable to specific literal values (e.g., `'small' | 'medium' | 'large'`).
124
+
- Restrict a variable to specific literal values (for example, `'small' | 'medium' | 'large'`).
125
125
- Example:
126
126
127
127
```bicep
@@ -241,30 +241,6 @@ Markdown-formatted text can be used for the description text.
241
241
242
242
Use `@export()` to share the variable with other Bicep files. For more information, see [Export variables, types, and functions](./bicep-import.md#export-variables-types-and-functions).
243
243
244
-
## Use variables
245
-
246
-
The following example shows how to use the variable for a resource property. You reference the value for the variable by providing the variable's name: `storageName`.
247
-
248
-
```bicep
249
-
param rgLocation string
250
-
param storageNamePrefix string = 'STG'
251
-
252
-
var storageName = '${toLower(storageNamePrefix)}${uniqueString(resourceGroup().id)}'
Because storage account names must use lowercase letters, the `storageName` variable uses the `toLower` function to make the `storageNamePrefix` value lowercase. The `uniqueString` function creates a unique value from the resource group ID. The values are concatenated to a string.
267
-
268
244
## Configuration variables
269
245
270
246
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