Skip to content

Commit d30e4b6

Browse files
committed
update
1 parent 25bd46e commit d30e4b6

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

articles/azure-resource-manager/bicep/variables.md

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A variable can't have the same name as a parameter, module, or resource. You can
1818

1919
### Untyped variables
2020

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:
2222

2323
```bicep
2424
@<decorator>(<argument>)
@@ -68,7 +68,7 @@ var storageName = '${toLower(storageNamePrefix)}${uniqueString(resourceGroup().i
6868
output uniqueStorageName string = storageName
6969
```
7070

71-
The preceding example returns a value like the following:
71+
The preceding example returns a value like the following output:
7272

7373
```json
7474
"uniqueStorageName": {
@@ -79,7 +79,7 @@ The preceding example returns a value like the following:
7979

8080
### Typed variables
8181

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:
8383

8484
- **Error detection**: The Bicep compiler validates that assigned values match the declared type, catching errors early.
8585
- **Code clarity**: Explicit types make it clear what kind of data a variable holds.
@@ -106,22 +106,22 @@ var subnets: array = ['subnet1', 'subnet2']
106106
Bicep supports the following types for variables:
107107

108108
- **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`)
111111
- `bool`: Boolean values (`true` or `false`)
112112
- **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' }`)
115115
- **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`).
117117
- Example:
118118

119119
```bicep
120120
var flexibleId: string | int = 'resource123'
121121
```
122122
123123
- **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'`).
125125
- Example:
126126
127127
```bicep
@@ -241,30 +241,6 @@ Markdown-formatted text can be used for the description text.
241241

242242
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).
243243

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)}'
253-
254-
resource demoAccount 'Microsoft.Storage/storageAccounts@2024-01-01' = {
255-
name: storageName
256-
location: rgLocation
257-
kind: 'Storage'
258-
sku: {
259-
name: 'Standard_LRS'
260-
}
261-
}
262-
263-
output stgOutput string = storageName
264-
```
265-
266-
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-
268244
## Configuration variables
269245

270246
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

Comments
 (0)