Skip to content

Commit b5dd600

Browse files
author
Jill Grant
authored
Merge pull request #285062 from mumian/0812-bicep-export
Refresh and restructure the Decorator content
2 parents 0da783b + a67d09b commit b5dd600

14 files changed

+465
-189
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ title: Imports in Bicep
33
description: Describes how to import shared functionality and namespaces in Bicep.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 08/07/2024
6+
ms.date: 08/20/2024
77
---
88

99
# Imports in Bicep
1010

11-
This article describes the syntax you use to export and import shared functionality, as well as namespaces for Bicep extensions.
11+
This article describes the syntax you use to export and import shared functionality, and namespaces for Bicep extensions.
1212

13-
## Exporting types, variables and functions
13+
## Export variables, types, and functions
1414

15-
The `@export()` decorator indicates that a given statement can be imported by another file. This decorator is only valid on type, variable, and function statements. Variable statements marked with `@export()` must be compile-time constants.
15+
The `@export()` decorator indicates that a given statement can be imported by another file. This decorator is only valid on [`type`](./user-defined-data-types.md), [`var`](./variables.md), and [`func`](./user-defined-functions.md) statements. Variable statements marked with `@export()` must be compile-time constants.
1616

1717
The syntax for exporting functionality for use in other Bicep files is:
1818

@@ -21,7 +21,7 @@ The syntax for exporting functionality for use in other Bicep files is:
2121
<statement_to_export>
2222
```
2323

24-
## Import types, variables, and functions
24+
## Import variables, types, and functions
2525

2626
The syntax for importing functionality from another Bicep file is:
2727

@@ -43,7 +43,7 @@ import * as <alias_name> from '<bicep_file_name>'
4343

4444
You can mix and match the preceding syntaxes. To access imported symbols using the wildcard syntax, you must use the `.` operator: `<alias_name>.<exported_symbol>`.
4545

46-
Only statements that have been [exported](#exporting-types-variables-and-functions) in the file being referenced are available to be imported.
46+
Only statements that have been [exported](#export-variables-types-and-functions) in the file being referenced are available to be imported.
4747

4848
Functionality that has been imported from another file can be used without restrictions. For example, imported variables can be used anywhere a variable declared in-file would normally be valid.
4949

articles/azure-resource-manager/bicep/data-types.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Data types in Bicep
33
description: Describes the data types that are available in Bicep
44
ms.topic: reference
55
ms.custom: devx-track-bicep
6-
ms.date: 07/16/2024
6+
ms.date: 08/20/2024
77
---
88

99
# Data types in Bicep
@@ -319,7 +319,7 @@ is ${blocked}'''
319319

320320
## Union types
321321

322-
In Bicep, a union type allows the creation of a combined type consisting of a set of sub-types. An assignment is valid if any of the individual sub-type assignments are permitted. The `|` character separates individual sub-types using an _or_ condition. For example, the syntax _'a' | 'b'_ means that a valid assignment could be either _'a'_ or _'b'_. Union types are translated into the [allowed-value](../templates/definitions.md#allowed-values) constraint in Bicep, so only literals are permitted as members. Unions can include any number of literal-typed expressions.
322+
In Bicep, a union type allows the creation of a combined type consisting of a set of subtypes. An assignment is valid if any of the individual subtype assignments are permitted. The `|` character separates individual subtypes using an _or_ condition. For example, the syntax _'a' | 'b'_ means that a valid assignment could be either _'a'_ or _'b'_. Union types are translated into the [allowed-value](../templates/definitions.md#allowed-values) constraint in Bicep, so only literals are permitted as members. Unions can include any number of literal-typed expressions.
323323

324324
```bicep
325325
type color = 'Red' | 'Blue' | 'White'
@@ -335,7 +335,7 @@ Type unions must be reducible to a single ARM type, such as 'string', 'int', or
335335
type foo = 'a' | 1
336336
```
337337

338-
Any type expression can be used as a sub-type in a union type declaration (between `|` characters). For example, the following examples are all valid:
338+
Any type expression can be used as a subtype in a union type declaration (between `|` characters). For example, the following examples are all valid:
339339

340340
```bicep
341341
type foo = 1 | 2
@@ -379,13 +379,13 @@ There are some limitations with union type.
379379
```
380380

381381
* Only literals are permitted as members.
382-
* All literals must be of the same primitive data type (e.g., all strings or all integers).
382+
* All literals must be of the same primitive data type (for example, all strings or all integers).
383383

384384
The union type syntax can be used in [user-defined data types](./user-defined-data-types.md).
385385

386386
## Secure strings and objects
387387

388-
Secure string uses the same format as string, and secure object uses the same format as object. With Bicep, you add the `@secure()` [decorator](./parameters.md#decorators) to a string or object.
388+
Secure string uses the same format as string, and secure object uses the same format as object. With Bicep, you add the `@secure()` [decorator](./parameters.md#use-decorators) to a string or object.
389389

390390
When you set a parameter to a secure string or secure object, the value of the parameter isn't saved to the deployment history and isn't logged. However, if you set that secure value to a property that isn't expecting a secure value, the value isn't protected. For example, if you set a secure string to a tag, that value is stored as plain text. Use secure strings for passwords and secrets.
391391

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

Lines changed: 84 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep file structure and syntax
33
description: Describes the structure and properties of a Bicep file using declarative syntax.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 07/11/2024
6+
ms.date: 08/20/2024
77
---
88

99
# Understand the structure and syntax of Bicep files
@@ -23,19 +23,24 @@ metadata <metadata-name> = ANY
2323
2424
targetScope = '<scope>'
2525
26+
@<decorator>(<argument>)
2627
type <user-defined-data-type-name> = <type-expression>
2728
29+
@<decorator>(<argument>)
2830
func <user-defined-function-name> (<argument-name> <data-type>, <argument-name> <data-type>, ...) <function-data-type> => <expression>
2931
3032
@<decorator>(<argument>)
3133
param <parameter-name> <parameter-data-type> = <default-value>
3234
35+
@<decorator>(<argument>)
3336
var <variable-name> = <variable-value>
3437
38+
@<decorator>(<argument>)
3539
resource <resource-symbolic-name> '<resource-type>@<api-version>' = {
3640
<resource-properties>
3741
}
3842
43+
@<decorator>(<argument>)
3944
module <module-symbolic-name> '<path-to-file>' = {
4045
name: '<linked-deployment-name>'
4146
params: {
@@ -99,6 +104,74 @@ The allowed values are:
99104

100105
In a module, you can specify a scope that is different than the scope for the rest of the Bicep file. For more information, see [Configure module scope](modules.md#set-module-scope)
101106

107+
## Decorators
108+
109+
You can add one or more decorators for each of the following elements:
110+
111+
* [param](#parameters)
112+
* [var](#variables)
113+
* [resource](#resources)
114+
* [module](#modules)
115+
* [output](#outputs)
116+
* [func](#functions)
117+
* [type](#types)
118+
119+
| Decorator | Apply to element | Apply to data type | Argument | Description |
120+
| --------- | ---- | ----------- | ------- |
121+
| allowed | [param](./parameters.md#allowed-values) | all | array | Use this decorator to make sure the user provides correct values. This decorator is only permitted on `param` statements. To declare that a property must be one of a set of predefined values in a [`type`](./user-defined-data-types.md) or [`output`](./outputs.md) statement, use [union type syntax](./data-types.md#union-types). Union type syntax can also be used in `param` statements.|
122+
| batchSize |[resource](./resource-declaration.md#batchsize), [module](./modules.md#batchsize)| N/A | integer | Set up instances to deploy sequentially. |
123+
| description | [param](./parameters.md#description), [var](./variables.md#description), [resource](./resource-declaration.md#description), [module](./modules.md#description), [output](./outputs.md#description), [type](./user-defined-data-types.md#description), [func](./user-defined-functions.md#description) | all | string | Provide descriptions for the elements. Markdown-formatted text can be used for the description text. |
124+
| discriminator | [param](./parameters.md#discriminator), [type](./user-defined-data-types.md#discriminator), [output](./outputs.md#discriminator) | object | string | Use this decorator to ensure the correct subclass is identified and managed. For more information, see [Custom-tagged union data type](./data-types.md#custom-tagged-union-data-type).|
125+
| export | [var](./variables.md#export), [type](./user-defined-data-types.md#export), [func](./user-defined-functions.md#export) | all | none| Indicates that the element can be imported by another Bicep file. |
126+
| maxLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints) | array, string | int | The maximum length for string and array elements. The value is inclusive. |
127+
| maxValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints) | int | int | The maximum value for the integer elements. This value is inclusive. |
128+
| metadata | [param](./parameters.md#metadata), [output](./outputs.md#metadata) | all | object | Custom properties to apply to the elements. Can include a description property that is equivalent to the description decorator. |
129+
| minLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints) | array, string | int | The minimum length for string and array elements. The value is inclusive. |
130+
| minValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints) | int | int | The minimum value for the integer elements. This value is inclusive. |
131+
| sealed | [param](./parameters.md#sealed), [type](./user-defined-data-types.md#sealed), [output](./outputs.md#sealed) | object | none | Elevate [BCP089](./diagnostics/bcp089.md) from a warning to an error when a property name of a use-define data type is likely a typo. For more information, see [Elevate error level](./user-defined-data-types.md#elevate-error-level). |
132+
| secure | [param](./parameters.md#secure-parameters) | string, object | none | Marks the parameter as secure. The value for a secure parameter isn't saved to the deployment history and isn't logged. For more information, see [Secure strings and objects](data-types.md#secure-strings-and-objects). |
133+
134+
## Parameters
135+
136+
Use parameters for values that need to vary for different deployments. You can define a default value for the parameter that is used if no value is provided during deployment.
137+
138+
For example, you can add a SKU parameter to specify different sizes for a resource. You might pass in different values depending on whether you're deploying to test or production.
139+
140+
```bicep
141+
param storageSKU string = 'Standard_LRS'
142+
```
143+
144+
The parameter is available for use in your Bicep file.
145+
146+
```bicep
147+
sku: {
148+
name: storageSKU
149+
}
150+
```
151+
152+
You can add one or more decorators for each parameter. For more information, see [Use decorators](./parameters.md#use-decorators).
153+
154+
For more information, see [Parameters in Bicep](./parameters.md).
155+
156+
## Variables
157+
158+
You can make your Bicep file more readable by encapsulating complex expressions in a variable. For example, you might add a variable for a resource name that is constructed by concatenating several values together.
159+
160+
```bicep
161+
var uniqueStorageName = '${storagePrefix}${uniqueString(resourceGroup().id)}'
162+
```
163+
164+
Apply this variable wherever you need the complex expression.
165+
166+
```bicep
167+
resource stg 'Microsoft.Storage/storageAccounts@2023-04-01' = {
168+
name: uniqueStorageName
169+
```
170+
171+
You can add one or more decorators for each variable. For more information, see [Use decorators](./variables.md#use-decorators).
172+
173+
For more information, see [Variables in Bicep](./variables.md).
174+
102175
## Types
103176

104177
You can use the `type` statement to define user-defined data types.
@@ -128,6 +201,8 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2023-04-01' = {
128201
}
129202
```
130203

204+
You can add one or more decorators for each user-defined data type. For more information, see [Use decorators](./user-defined-data-types.md#use-decorators).
205+
131206
For more information, see [User-defined data types](./user-defined-data-types.md).
132207

133208
## Functions
@@ -142,59 +217,6 @@ output azureUrl string = buildUrl(true, 'microsoft.com', 'azure')
142217

143218
For more information, see [User-defined functions](./user-defined-functions.md).
144219

145-
## Parameters
146-
147-
Use parameters for values that need to vary for different deployments. You can define a default value for the parameter that is used if no value is provided during deployment.
148-
149-
For example, you can add a SKU parameter to specify different sizes for a resource. You might pass in different values depending on whether you're deploying to test or production.
150-
151-
```bicep
152-
param storageSKU string = 'Standard_LRS'
153-
```
154-
155-
The parameter is available for use in your Bicep file.
156-
157-
```bicep
158-
sku: {
159-
name: storageSKU
160-
}
161-
```
162-
163-
For more information, see [Parameters in Bicep](./parameters.md).
164-
165-
## Parameter decorators
166-
167-
You can add one or more decorators for each parameter. These decorators describe the parameter and define constraints for the values that are passed in. The following example shows one decorator but many others are available.
168-
169-
```bicep
170-
@allowed([
171-
'Standard_LRS'
172-
'Standard_GRS'
173-
'Standard_ZRS'
174-
'Premium_LRS'
175-
])
176-
param storageSKU string = 'Standard_LRS'
177-
```
178-
179-
For more information, including descriptions of all available decorators, see [Decorators](parameters.md#decorators).
180-
181-
## Variables
182-
183-
You can make your Bicep file more readable by encapsulating complex expressions in a variable. For example, you might add a variable for a resource name that is constructed by concatenating several values together.
184-
185-
```bicep
186-
var uniqueStorageName = '${storagePrefix}${uniqueString(resourceGroup().id)}'
187-
```
188-
189-
Apply this variable wherever you need the complex expression.
190-
191-
```bicep
192-
resource stg 'Microsoft.Storage/storageAccounts@2023-04-01' = {
193-
name: uniqueStorageName
194-
```
195-
196-
For more information, see [Variables in Bicep](./variables.md).
197-
198220
## Resources
199221

200222
Use the `resource` keyword to define a resource to deploy. Your resource declaration includes a symbolic name for the resource. You use this symbolic name in other parts of the Bicep file to get a value from the resource.
@@ -215,6 +237,8 @@ resource stg 'Microsoft.Storage/storageAccounts@2023-04-01' = {
215237
}
216238
```
217239

240+
You can add one or more decorators for each resource. For more information, see [Use decorators](./resource-declaration.md#use-decorators).
241+
218242
For more information, see [Resource declaration in Bicep](resource-declaration.md).
219243

220244
Some resources have a parent/child relationship. You can define a child resource either inside the parent resource or outside of it.
@@ -281,22 +305,9 @@ module webModule './webApp.bicep' = {
281305

282306
The symbolic name enables you to reference the module from somewhere else in the file. For example, you can get an output value from a module by using the symbolic name and the name of the output value.
283307

284-
For more information, see [Use Bicep modules](./modules.md).
285-
286-
## Resource and module decorators
287-
288-
You can add a decorator to a resource or module definition. The supported decorators are `batchSize(int)` and `description`. You can only apply it to a resource or module definition that uses a `for` expression.
289-
290-
By default, resources are deployed in parallel. When you add the `batchSize(int)` decorator, you deploy instances serially.
291-
292-
```bicep
293-
@batchSize(3)
294-
resource storageAccountResources 'Microsoft.Storage/storageAccounts@2023-04-01' = [for storageName in storageAccounts: {
295-
...
296-
}]
297-
```
308+
You can add one or more decorators for each module. For more information, see [Use decorators](./modules.md#use-decorators).
298309

299-
For more information, see [Deploy in batches](loops.md#deploy-in-batches).
310+
For more information, see [Use Bicep modules](./modules.md).
300311

301312
## Outputs
302313

@@ -306,6 +317,8 @@ Use outputs to return values from the deployment. Typically, you return a value
306317
output storageEndpoint object = stg.properties.primaryEndpoints
307318
```
308319

320+
You can add one or more decorators for each output. For more information, see [Use decorators](./outputs.md#use-decorators).
321+
309322
For more information, see [Outputs in Bicep](./outputs.md).
310323

311324
## Loops
@@ -423,7 +436,7 @@ The preceding example is equivalent to the following JSON.
423436

424437
## Multiple-line declarations
425438

426-
You can now use multiple lines in function, array and object declarations. This feature requires [Bicep CLI version 0.7.X or higher](./install.md).
439+
You can now use multiple lines in function, array, and object declarations. This feature requires [Bicep CLI version 0.7.X or higher](./install.md).
427440

428441
In the following example, the `resourceGroup()` definition is broken into multiple lines.
429442

@@ -438,7 +451,7 @@ See [Arrays](./data-types.md#arrays) and [Objects](./data-types.md#objects) for
438451
## Known limitations
439452

440453
* No support for the concept of apiProfile, which is used to map a single apiProfile to a set apiVersion for each resource type.
441-
* User-defined functions are not supported at the moment. However, an experimental feature is currently accessible. For more information, see [User-defined functions in Bicep](./user-defined-functions.md).
454+
* User-defined functions aren't supported at the moment. However, an experimental feature is currently accessible. For more information, see [User-defined functions in Bicep](./user-defined-functions.md).
442455
* Some Bicep features require a corresponding change to the intermediate language (Azure Resource Manager JSON templates). We announce these features as available when all of the required updates have been deployed to global Azure. If you're using a different environment, such as Azure Stack, there may be a delay in the availability of the feature. The Bicep feature is only available when the intermediate language has also been updated in that environment.
443456

444457
## Next steps

articles/azure-resource-manager/bicep/linter-rule-secure-secrets-in-parameters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.date: 03/20/2024
88

99
# Linter rule - secure secrets in parameters
1010

11-
This rule finds parameters whose names look like secrets but without the [secure decorator](./parameters.md#decorators), for example: a parameter name contains the following keywords:
11+
This rule finds parameters whose names look like secrets but without the [secure decorator](./parameters.md#use-decorators), for example: a parameter name contains the following keywords:
1212

1313
- password
1414
- pwd
@@ -24,7 +24,7 @@ Use the following value in the [Bicep configuration file](bicep-config-linter.md
2424

2525
## Solution
2626

27-
Use the [secure decorator](./parameters.md#decorators) for the parameters that contain secrets. The secure decorator marks the parameter as secure. The value for a secure parameter isn't saved to the deployment history and isn't logged.
27+
Use the [secure decorator](./parameters.md#use-decorators) for the parameters that contain secrets. The secure decorator marks the parameter as secure. The value for a secure parameter isn't saved to the deployment history and isn't logged.
2828

2929
The following example fails this test because the parameter name may contain secrets.
3030

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ By default, Azure resources are deployed in parallel. When you use a loop to cre
309309

310310
You might not want to update all instances of a resource type at the same time. For example, when updating a production environment, you may want to stagger the updates so only a certain number are updated at any one time. You can specify that a subset of the instances be batched together and deployed at the same time. The other instances wait for that batch to complete.
311311

312-
To serially deploy instances of a resource, add the [batchSize decorator](./file.md#resource-and-module-decorators). Set its value to the number of instances to deploy concurrently. A dependency is created on earlier instances in the loop, so it doesn't start one batch until the previous batch completes.
312+
To serially deploy instances of a resource, add the [batchSize decorator](./file.md#decorators). Set its value to the number of instances to deploy concurrently. A dependency is created on earlier instances in the loop, so it doesn't start one batch until the previous batch completes.
313313

314314
```bicep
315315
param location string = resourceGroup().location

0 commit comments

Comments
 (0)