Skip to content

Commit 9ca80ff

Browse files
authored
Merge pull request #310587 from mumian/0115-directive
Using directives
2 parents 506bbec + 3f9a4ed commit 9ca80ff

4 files changed

Lines changed: 142 additions & 95 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ ms.custom:
77
- devx-track-bicep
88
- devx-track-arm-template
99
- build-2025
10-
ms.date: 01/15/2026
10+
ms.date: 01/16/2026
1111
---
1212

1313
# Bicep core diagnostics
1414

1515
If you need more information about a particular diagnostic code, select the **Feedback** button in the upper-right corner of the page and specify the code.
1616

17+
You can suppress Bicep diagnostic codes by using the `disable-next-line` directive. See [`disable-next-line`](./file.md#disable-next-line).
18+
1719
| Code | Level | Description |
1820
|------------|-------|-------------|
1921
| <a id='BCP001' />BCP001 | Error | The following token isn't recognized: `{token}`. |

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

Lines changed: 126 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ This article describes the structure and syntax of a Bicep file. It presents the
1212

1313
For a step-by-step tutorial that guides you through the process of creating a Bicep file, see [Quickstart: Create Bicep files with Visual Studio Code](./quickstart-create-bicep-use-visual-studio-code.md).
1414

15+
## Known limitations
16+
17+
* Support isn't available for the concept of `apiProfile`, which is used to map a single `apiProfile` to a set `apiVersion` for each resource type.
18+
* User-defined functions aren't supported at this time. An experimental feature is currently accessible. For more information, see [User-defined functions in Bicep](./user-defined-functions.md).
19+
* Some Bicep features require a corresponding change to the intermediate language (Azure Resource Manager JSON templates). We announce these features as available after all the required updates are deployed to global Azure. If you use a different environment such as Azure Stack, there might be a delay in the availability of the feature. The Bicep feature is available only after the intermediate language is also updated in that environment.
20+
1521
## Bicep format
1622

1723
Bicep is a declarative language, which means the elements can appear in any order. Unlike imperative languages, the order of elements doesn't affect how deployment is processed.
1824

1925
A Bicep file has the following elements:
2026

2127
```bicep
28+
#<directive-name> <argument> [<argument> ...]
29+
2230
@<decorator>(<argument>)
2331
metadata <metadata-name> = ANY
2432
@@ -106,35 +114,6 @@ The allowed values are:
106114

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

109-
## Decorators
110-
111-
You can add one or more decorators for each of the following elements:
112-
113-
* [param](#parameters)
114-
* [var](#variables)
115-
* [resource](#resources)
116-
* [module](#modules)
117-
* [output](#outputs)
118-
* [func](#functions)
119-
* [type](#types)
120-
121-
The following table lists the decorators:
122-
123-
| Decorator | Apply to element | Apply to data type | Argument | Description |
124-
| --------- | ---- | ----------- | ------- |
125-
| allowed | [param](./parameters.md#allowed-values) | all | array | Use this decorator to make sure the user provides correct values. This decorator is permitted only 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). You can also use union type syntax in `param` statements.|
126-
| batchSize |[module](./modules.md#batchsize), [resource](./resource-declaration.md#batchsize) | N/A | integer | Set up instances to deploy sequentially. |
127-
| description | [func](./user-defined-functions.md#description), [param](./parameters.md#description), [module](./modules.md#description), [output](./outputs.md#description), [resource](./resource-declaration.md#description), [type](./user-defined-data-types.md#description), [var](./variables.md#description) | all | string | Provide descriptions for the elements. Use Markdown-formatted text for the description text. |
128-
| discriminator | [param](./parameters.md#discriminator), [type](./user-defined-data-types.md#discriminator), [output](./outputs.md#discriminator) | object | string | Use this decorator to ensure that the correct subclass is identified and managed. For more information, see [Custom-tagged union data type](./data-types.md#custom-tagged-union-data-type).|
129-
| export | [func](./user-defined-functions.md#export), [type](./user-defined-data-types.md#export), [var](./variables.md#export) | all | none| Indicates that another Bicep file can import the element. |
130-
| maxLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints), [type](./user-defined-data-types.md#length-constraints) | array, string | int | The maximum length for string and array elements. The value is inclusive. |
131-
| maxValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints), [type](./user-defined-data-types.md#integer-constraints) | int | int | The maximum value for the integer elements. This value is inclusive. |
132-
| metadata | [func](./user-defined-functions.md#metadata), [output](./outputs.md#metadata), [param](./parameters.md#metadata), [type](./user-defined-data-types.md#metadata) | all | object | Custom properties to apply to the elements. Can include a description property that's equivalent to the description decorator. |
133-
| minLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints), [type](./user-defined-data-types.md#length-constraints) | array, string | int | The minimum length for string and array elements. The value is inclusive. |
134-
| minValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints), [type](./user-defined-data-types.md#integer-constraints) | int | int | The minimum value for the integer elements. This value is inclusive. |
135-
| 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 user-defined data type is likely a typo. For more information, see [Elevate error level](./user-defined-data-types.md#elevate-error-level). |
136-
| secure | [param](./parameters.md#secure-parameters), [type](./user-defined-data-types.md#secure-types) | 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). |
137-
138117
## Parameters
139118

140119
Use parameters for values that need to vary for different deployments. You can define a default value for the parameter that's used if a value isn't provided during deployment.
@@ -176,51 +155,6 @@ You can add one or more decorators for each variable. For more information, see
176155

177156
For more information, see [Variables in Bicep](./variables.md).
178157

179-
## Types
180-
181-
You can use the `type` statement to define user-defined data types.
182-
183-
```bicep
184-
param location string = resourceGroup().location
185-
186-
type storageAccountSkuType = 'Standard_LRS' | 'Standard_GRS'
187-
188-
type storageAccountConfigType = {
189-
name: string
190-
sku: storageAccountSkuType
191-
}
192-
193-
param storageAccountConfig storageAccountConfigType = {
194-
name: 'storage${uniqueString(resourceGroup().id)}'
195-
sku: 'Standard_LRS'
196-
}
197-
198-
resource storageAccount 'Microsoft.Storage/storageAccounts@2025-06-01' = {
199-
name: storageAccountConfig.name
200-
location: location
201-
sku: {
202-
name: storageAccountConfig.sku
203-
}
204-
kind: 'StorageV2'
205-
}
206-
```
207-
208-
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).
209-
210-
For more information, see [User-defined data types in Bicep](./user-defined-data-types.md).
211-
212-
## Functions
213-
214-
In your Bicep file, you can create your own functions and also use the [standard Bicep functions](./bicep-functions.md) that are automatically available within your Bicep files. Create your own functions when you have complicated expressions that are used repeatedly in your Bicep files.
215-
216-
```bicep
217-
func buildUrl(https bool, hostname string, path string) string => '${https ? 'https' : 'http'}://${hostname}${empty(path) ? '' : '/${path}'}'
218-
219-
output azureUrl string = buildUrl(true, 'microsoft.com', 'azure')
220-
```
221-
222-
For more information, see [User-defined functions in Bicep](./user-defined-functions.md).
223-
224158
## Resources
225159

226160
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.
@@ -325,6 +259,124 @@ You can add one or more decorators for each output. For more information, see [U
325259

326260
For more information, see [Outputs in Bicep](./outputs.md).
327261

262+
## Types
263+
264+
You can use the `type` statement to define user-defined data types.
265+
266+
```bicep
267+
param location string = resourceGroup().location
268+
269+
type storageAccountSkuType = 'Standard_LRS' | 'Standard_GRS'
270+
271+
type storageAccountConfigType = {
272+
name: string
273+
sku: storageAccountSkuType
274+
}
275+
276+
param storageAccountConfig storageAccountConfigType = {
277+
name: 'storage${uniqueString(resourceGroup().id)}'
278+
sku: 'Standard_LRS'
279+
}
280+
281+
resource storageAccount 'Microsoft.Storage/storageAccounts@2025-06-01' = {
282+
name: storageAccountConfig.name
283+
location: location
284+
sku: {
285+
name: storageAccountConfig.sku
286+
}
287+
kind: 'StorageV2'
288+
}
289+
```
290+
291+
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).
292+
293+
For more information, see [User-defined data types in Bicep](./user-defined-data-types.md).
294+
295+
## Functions
296+
297+
In your Bicep file, you can create your own functions and also use the [standard Bicep functions](./bicep-functions.md) that are automatically available within your Bicep files. Create your own functions when you have complicated expressions that are used repeatedly in your Bicep files.
298+
299+
```bicep
300+
func buildUrl(https bool, hostname string, path string) string => '${https ? 'https' : 'http'}://${hostname}${empty(path) ? '' : '/${path}'}'
301+
302+
output azureUrl string = buildUrl(true, 'microsoft.com', 'azure')
303+
```
304+
305+
For more information, see [User-defined functions in Bicep](./user-defined-functions.md).
306+
307+
## Decorators
308+
309+
You can add one or more decorators for each of the following elements:
310+
311+
* [param](#parameters)
312+
* [var](#variables)
313+
* [resource](#resources)
314+
* [module](#modules)
315+
* [output](#outputs)
316+
* [func](#functions)
317+
* [type](#types)
318+
319+
The following table lists the decorators:
320+
321+
| Decorator | Apply to element | Apply to data type | Argument | Description |
322+
| --------- | ---- | ----------- | ------- |
323+
| allowed | [param](./parameters.md#allowed-values) | all | array | Use this decorator to make sure the user provides correct values. This decorator is permitted only 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). You can also use union type syntax in `param` statements.|
324+
| batchSize |[module](./modules.md#batchsize), [resource](./resource-declaration.md#batchsize) | N/A | integer | Set up instances to deploy sequentially. |
325+
| description | [func](./user-defined-functions.md#description), [param](./parameters.md#description), [module](./modules.md#description), [output](./outputs.md#description), [resource](./resource-declaration.md#description), [type](./user-defined-data-types.md#description), [var](./variables.md#description) | all | string | Provide descriptions for the elements. Use Markdown-formatted text for the description text. |
326+
| discriminator | [param](./parameters.md#discriminator), [type](./user-defined-data-types.md#discriminator), [output](./outputs.md#discriminator) | object | string | Use this decorator to ensure that the correct subclass is identified and managed. For more information, see [Custom-tagged union data type](./data-types.md#custom-tagged-union-data-type).|
327+
| export | [func](./user-defined-functions.md#export), [type](./user-defined-data-types.md#export), [var](./variables.md#export) | all | none| Indicates that another Bicep file can import the element. |
328+
| maxLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints), [type](./user-defined-data-types.md#length-constraints) | array, string | int | The maximum length for string and array elements. The value is inclusive. |
329+
| maxValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints), [type](./user-defined-data-types.md#integer-constraints) | int | int | The maximum value for the integer elements. This value is inclusive. |
330+
| metadata | [func](./user-defined-functions.md#metadata), [output](./outputs.md#metadata), [param](./parameters.md#metadata), [type](./user-defined-data-types.md#metadata) | all | object | Custom properties to apply to the elements. Can include a description property that's equivalent to the description decorator. |
331+
| minLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints), [type](./user-defined-data-types.md#length-constraints) | array, string | int | The minimum length for string and array elements. The value is inclusive. |
332+
| minValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints), [type](./user-defined-data-types.md#integer-constraints) | int | int | The minimum value for the integer elements. This value is inclusive. |
333+
| 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 user-defined data type is likely a typo. For more information, see [Elevate error level](./user-defined-data-types.md#elevate-error-level). |
334+
| secure | [param](./parameters.md#secure-parameters), [type](./user-defined-data-types.md#secure-types) | 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). |
335+
336+
## Directives
337+
338+
Directives provide instructions to the Bicep compiler and linter without affecting the runtime behavior of a template. You write directives as comments. The compiler evaluates them during compilation and validation.
339+
340+
A directive uses the following general syntax:
341+
342+
```bicep
343+
#<directive-name> <argument1> [<argument2> ... ]
344+
```
345+
346+
You separate arguments by using spaces. The specific directive determines how to interpret the arguments.
347+
348+
### `disable-next-line`
349+
350+
Use the `#disable-next-line` directive to suppress diagnostics for the statement immediately following the directive. You must specify at least one identifier after the directive. If you don't provide any identifiers, the compiler reports an error. The identifiers you specify after the directive can refer to:
351+
352+
* [Bicep compiler diagnostics](./bicep-core-diagnostics.md), such as `BCP138`
353+
* [Bicep linter rules](./linter.md), such as `no-unused-params`
354+
355+
The following example suppresses a compiler diagnostic:
356+
357+
```bicep
358+
#disable-next-line BCP138
359+
resource stg 'Microsoft.Storage/storageAccounts@2025-06-01' = {
360+
name: 'examplestorage'
361+
}
362+
```
363+
364+
The following example suppresses a linter rule:
365+
366+
```bicep
367+
#disable-next-line no-unused-params
368+
param unusedParam string
369+
```
370+
371+
The following example suppresses multiple diagnostics and rules:
372+
373+
```bicep
374+
#disable-next-line BCP138 no-unused-params
375+
param example string
376+
```
377+
378+
Use directives sparingly and only when you review and intentionally suppress a diagnostic or linter rule. Excessive use can reduce template readability and maintainability. Add a comment explaining why the rules or the diagnostic codes don't apply to this line.
379+
328380
## Loops
329381

330382
Add iterative loops to your Bicep file to define multiple copies of:
@@ -452,12 +504,6 @@ var foo = resourceGroup(
452504

453505
For multiple-line declaration samples, see [arrays](./data-types.md#arrays) and [objects](./data-types.md#objects).
454506

455-
## Known limitations
456-
457-
* Support isn't available for the concept of `apiProfile`, which is used to map a single `apiProfile` to a set `apiVersion` for each resource type.
458-
* User-defined functions aren't supported at this time. An experimental feature is currently accessible. For more information, see [User-defined functions in Bicep](./user-defined-functions.md).
459-
* Some Bicep features require a corresponding change to the intermediate language (Azure Resource Manager JSON templates). We announce these features as available after all the required updates are deployed to global Azure. If you use a different environment such as Azure Stack, there might be a delay in the availability of the feature. The Bicep feature is available only after the intermediate language is also updated in that environment.
460-
461507
## Related content
462508

463509
* For an introduction to Bicep, see [What is Bicep?](./overview.md).

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Use Bicep linter
33
description: Learn how to use Bicep linter.
44
ms.topic: how-to
55
ms.custom: devx-track-bicep
6-
ms.date: 12/22/2025
6+
ms.date: 01/16/2026
77
---
88

99
# Use Bicep linter
@@ -92,19 +92,18 @@ You can integrate these checks as a part of your CI/CD pipelines. You can use a
9292

9393
## Silencing false positives
9494

95-
Sometimes a rule can have false positives. For example, you might need to include a link to a blob storage directly without using the [environment()](./bicep-functions-deployment.md#environment) function.
96-
In this case you can disable the warning for one line only, not the entire document, by adding `#disable-next-line <rule name>` before the line with the warning.
95+
Sometimes a rule has false positives. For example, you might need to include a link to a blob storage directly without using the [environment()](./bicep-functions-deployment.md#environment) function.
96+
97+
In this case, you can disable the warning for one line only, not the entire document, by adding the `#disable-next-line` directive before the line with the warning.
9798

9899
```bicep
99100
#disable-next-line no-hardcoded-env-urls //Direct download link to my toolset
100101
scriptDownloadUrl: 'https://mytools.blob.core.windows.net/...'
101102
```
102103

103-
Multiple codes may be listed, separated by spaces.
104-
105-
It's good practice to add a comment explaining why the rule doesn't apply to this line.
104+
For more information about using directives in Bicep, see [Directives](./file.md#directives).
106105

107-
If you want to suppress a linter rule, you can change the level of the rule to `Off` in [bicepconfig.json](./bicep-config-linter.md). For example, in the following example, the `no-deployments-resources` rule is suppressed:
106+
If you want to suppress a linter rule, change the level of the rule to `Off` in [bicepconfig.json](./bicep-config-linter.md). In the following example, the `no-deployments-resources` rule is suppressed:
108107

109108
```json
110109
{

0 commit comments

Comments
 (0)