Skip to content

Commit 759a6bd

Browse files
committed
incorporate review comments
1 parent d30e4b6 commit 759a6bd

File tree

2 files changed

+21
-46
lines changed

2 files changed

+21
-46
lines changed

articles/azure-resource-manager/bicep/diagnostics/bcp414.md

Whitespace-only changes.

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

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Variables in Bicep
33
description: Describes how to define variables in Bicep
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 05/15/2025
6+
ms.date: 05/30/2025
77
---
88

99
# Variables in Bicep
@@ -14,7 +14,7 @@ Resource Manager resolves variables before starting the deployment operations. W
1414

1515
## Define variables
1616

17-
A variable can't have the same name as a parameter, module, or resource. You can add one or more decorators for each variable. For more information, see Use [decorators](#use-decorators).
17+
A variable can't have the same name as a parameter, module, or resource. You can add one or more decorators for each variable. For more information, see Use [decorators](#use-decorators).
1818

1919
### Untyped variables
2020

@@ -79,59 +79,33 @@ The preceding example returns a value like the following output:
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+
Starting with [Bicep CLI version 0.36.X](https://github.com/Azure/bicep/releases/tag/v0.36.1), 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.
8686
- **Intellisense support**: Tools like Visual Studio Code provide better autocompletion and validation for typed variables.
8787
- **Refactoring safety**: Ensures that changes to variable assignments don’t inadvertently break type expectations.
8888

89-
To define a typed variable, use the `var` keyword followed by the variable name, a colon (`:`), the type, and the assigned value:
89+
To define a typed variable, use the `var` keyword followed by the variable name, the type, and the assigned value:
9090

9191
```bicep
92-
@<decorator>(<argument>)
93-
var <variable-name>: <data-type> = <variable-value>
92+
var <variable-name> <data-type> = <variable-value>
9493
```
9594

9695
The following examples show how to define typed variables:
9796

9897
```bicep
99-
var resourceName: string = 'myResource'
100-
var instanceCount: int = 3
101-
var isProduction: bool = true
102-
var tags: object = { environment: 'dev' }
103-
var subnets: array = ['subnet1', 'subnet2']
98+
var resourceName string = 'myResource'
99+
var instanceCount int = 3
100+
var isProduction bool = true
101+
var tags object = { environment: 'dev' }
102+
var subnets array = ['subnet1', 'subnet2']
104103
```
105104

106-
Bicep supports the following types for variables:
107-
108-
- **Primitive types**:
109-
- `string`: Text values (for example, `'hello'`)
110-
- `int`: Integer values (for example, `42`)
111-
- `bool`: Boolean values (`true` or `false`)
112-
- **Complex types**:
113-
- `array`: A list of values (for example, `[1, 2, 3]`)
114-
- `object`: A key-value collection (for example, `{ key: 'value' }`)
115-
- **Union types** (Bicep 0.4 or later):
116-
- Allows a variable to accept multiple types (for example, `string | int`).
117-
- Example:
118-
119-
```bicep
120-
var flexibleId: string | int = 'resource123'
121-
```
122-
123-
- **Literal types**:
124-
- Restrict a variable to specific literal values (for example, `'small' | 'medium' | 'large'`).
125-
- Example:
126-
127-
```bicep
128-
var size: 'small' | 'medium' | 'large' = 'medium'
129-
```
130-
131-
For `object` types, you can define a schema to enforce a specific structure.
105+
For `object` types, you can define a schema to enforce a specific structure. The compiler ensures the object adheres to the defined schema.
132106

133107
```bicep
134-
var config: {
108+
var config {
135109
name: string
136110
count: int
137111
enabled: bool
@@ -142,20 +116,21 @@ var config: {
142116
}
143117
```
144118

145-
The compiler ensures the object adheres to the defined schema.
146-
147119
The following example uses typed variables with decorators to enforce constraints:
148120

149121
```bicep
150122
@description('The environment to deploy to')
151123
@allowed(['dev', 'test', 'prod'])
152-
param environment: string = 'dev'
124+
param environment string = 'dev'
153125
154-
var instanceCount: int = environment == 'prod' ? 5 : 2
155-
var resourcePrefix: string = 'app'
156-
var tags: object = {
126+
var instanceCount int = environment == 'prod' ? 5 : 2
127+
var resourcePrefix string = 'app'
128+
var tags {
129+
environment: string
130+
deployedBy: string
131+
} = {
157132
environment: environment
158-
deployedBy: 'bicep'
133+
deployedBy: 'Bicep'
159134
}
160135
161136
resource storage 'Microsoft.Storage/storageAccounts@2023-01-01' = {
@@ -173,7 +148,7 @@ In this example:
173148

174149
- `instanceCount` is typed as `int` and uses a conditional expression.
175150
- `resourcePrefix` is typed as `string`.
176-
- `tags` is typed as `object` with a flexible structure.
151+
- `tags` is typed as `object` with a specific structure.
177152

178153
## Use iterative loops
179154

0 commit comments

Comments
 (0)