|
| 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). |
0 commit comments