Skip to content

Commit a578630

Browse files
committed
new linter rule - what-if-short-circuiting
1 parent 5dc75a6 commit a578630

File tree

4 files changed

+91
-2
lines changed

4 files changed

+91
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Linter settings for Bicep config
33
description: Describes how to customize configuration values for the Bicep linter
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 07/30/2024
6+
ms.date: 09/19/2024
77
---
88

99
# Add linter settings in the Bicep config file
@@ -135,6 +135,9 @@ The following example shows the rules that are available for configuration.
135135
},
136136
"use-stable-vm-image": {
137137
"level": "warning"
138+
},
139+
"what-if-short-circuiting": {
140+
"level": "warning"
138141
}
139142
}
140143
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: Linter rule - what-if short circuiting
3+
description: Linter rule - what-if short circuiting
4+
ms.topic: reference
5+
ms.custom: devx-track-bicep
6+
ms.date: 09/19/2024
7+
---
8+
9+
# Linter rule - what-if short circuiting
10+
11+
This rule detects runtime values used to determine resource IDs within modules and flags potential what-if short-circuiting.
12+
13+
> [!NOTE]
14+
> This rule is off by default, change the level in [bicepconfig.json](./bicep-config-linter.md) to enable it.
15+
16+
## Linter rule code
17+
18+
Use the following value in the [Bicep configuration file](bicep-config-linter.md) to customize rule settings:
19+
20+
`what-if-short-circuiting`
21+
22+
## Solution
23+
24+
This rule checks for runtime values that are used to determine resource IDs from within modules. It lets you know if your Bicep file will cuase what-if short circuiting. In the following example, **appServiceOutputs** and **appServiceTests** would both be flagged for what-if short circuiting becasue they pass runtime values as a parameter to the module which uses that when naming the resource:
25+
26+
This rule checks for runtime values used to determine resource IDs within modules. It alerts you if your Bicep file could cause what-if short-circuiting. In the example below, **appServiceOutputs** and **appServiceTests** would be flagged for what-if short-circuiting because they pass runtime values as parameters to the module, which uses them when naming the resource:
27+
28+
**main.bicep**
29+
30+
```bicep
31+
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
32+
name: 'storageAccountName'
33+
location: 'eastus'
34+
sku: {
35+
name: 'Standard_LRS'
36+
}
37+
kind: 'StorageV2'
38+
}
39+
40+
module appServiceModule 'modules/appService.bicep' = {
41+
name: 'appService2'
42+
params: {
43+
appServiceName: 'test'
44+
}
45+
}
46+
47+
module appServiceOutputs 'modules/appService.bicep' = {
48+
name: 'appService3'
49+
params: {
50+
appServiceName: appServiceModule.outputs.outputName
51+
}
52+
}
53+
54+
module appServiceTest 'modules/appService.bicep' = {
55+
name:'test3'
56+
params: {
57+
appServiceName: storageAccount.properties.accessTier
58+
}
59+
}
60+
```
61+
62+
**modules/appService.bicep**
63+
64+
```bicep
65+
param appServiceName string
66+
67+
resource appServiceApp 'Microsoft.Web/sites@2023-12-01' = {
68+
name: appServiceName
69+
location: 'eastus'
70+
properties: {
71+
httpsOnly: true
72+
}
73+
}
74+
75+
output outputName string = 'outputName'
76+
```
77+
78+
To avoid this issue, use deployment-time constants for values that are used in determining resource IDs.
79+
80+
## Next steps
81+
82+
For more information about the linter, see [Use Bicep linter](./linter.md).

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

Lines changed: 2 additions & 1 deletion
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: 07/30/2024
6+
ms.date: 09/19/2024
77
---
88

99
# Use Bicep linter
@@ -55,6 +55,7 @@ The default set of linter rules is minimal and taken from [arm-ttk test cases](.
5555
- [use-secure-value-for-secure-inputs](./linter-rule-use-secure-value-for-secure-inputs.md)
5656
- [use-stable-resource-identifiers](./linter-rule-use-stable-resource-identifier.md)
5757
- [use-stable-vm-image](./linter-rule-use-stable-vm-image.md)
58+
- [what-if-short-circuiting](./linter-rule-what-if-short-circuiting.md)
5859

5960
You can customize how the linter rules are applied. To overwrite the default settings, add a **bicepconfig.json** file and apply custom settings. For more information about applying those settings, see [Add custom settings in the Bicep config file](bicep-config-linter.md).
6061

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@
563563
- name: Use stable VM image
564564
displayName: linter
565565
href: linter-rule-use-stable-vm-image.md
566+
- name: What-if short-circuiting
567+
displayName: linter
568+
href: linter-rule-what-if-short-circuiting.md
566569
- name: Deploy
567570
items:
568571
- name: What-if check

0 commit comments

Comments
 (0)