Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This rule finds module parameters that are used for resource locations and may inadvertently default to an unexpected value.
Note
This rule is off by default. Change the level in bicepconfig.json to enable it.
Linter rule code
Use the following value in the Bicep configuration file to customize rule settings:
explicit-values-for-loc-params
Solution
When you consume a module, any ___location-related parameters that have a default value should be assigned an explicit value. Location-related parameters include parameters that have a default value referencing resourceGroup().___location
or deployment().___location
and also any parameter that is referenced from a resource's ___location property.
A parameter that defaults to a resource group's or deployment's ___location is convenient when a bicep file is used as a main deployment template. However, when such a default value is used in a module, it may cause unexpected behavior if the main template's resources aren't located in the same region as the resource group.
Examples
The following example fails this test. Module m1
's parameter ___location
isn't assigned an explicit value, so it defaults to resourceGroup().___location
, as specified in module1.bicep. But using the resource group ___location may not be the intended behavior, since other resources in main.bicep might be created in a different ___location than the resource group's ___location.
main.bicep:
param ___location string = 'eastus'
module m1 'module1.bicep' = {
name: 'm1'
}
resource storageaccount 'Microsoft.Storage/storageAccounts@2024-03-01' = {
name: 'storageaccount'
___location: ___location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
module1.bicep:
param ___location string = resourceGroup().___location
resource stg 'Microsoft.Storage/storageAccounts@2024-03-01' = {
name: 'stg'
___location: ___location
kind: 'StorageV2'
sku: {
name: 'Premium_LRS'
}
}
You can fix the failure by explicitly passing in a value for the module's ___location
property:
main.bicep:
param ___location string = 'eastus'
module m1 'module1.bicep' = {
name: 'm1'
params: {
___location: ___location // An explicit value will override the default value specified in module1.bicep
}
}
resource storageaccount 'Microsoft.Storage/storageAccounts@2024-03-01' = {
name: 'storageaccount'
___location: ___location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
Next steps
For more information about the linter, see Use Bicep linter.