Linter rule - no unnecessary dependsOn entries
This rule finds when an unnecessary dependsOn entry has been added to a resource or module declaration.
Linter rule code
Use the following value in the Bicep configuration file to customize rule settings:
no-unnecessary-dependson
Solution
To reduce confusion in your template, delete any dependsOn entries which are not necessary. Bicep automatically infers most resource dependencies as long as template expressions reference other resources via symbolic names rather than strings with hard-coded IDs or names.
The following example fails this test because the dependsOn entry appServicePlan is automatically inferred by Bicep implied by the expression appServicePlan.id (which references resource symbolic name appServicePlan) in the serverFarmId property's value.
resource appServicePlan 'Microsoft.Web/serverfarms@2020-12-01' = {
name: 'name'
location: resourceGroup().location
sku: {
name: 'F1'
capacity: 1
}
}
resource webApplication 'Microsoft.Web/sites@2018-11-01' = {
name: 'name'
location: resourceGroup().location
properties: {
serverFarmId: appServicePlan.id
}
dependsOn: [
appServicePlan
]
}
You can fix it by removing the unnecessary dependsOn entry.
resource appServicePlan 'Microsoft.Web/serverfarms@2020-12-01' = {
name: 'name'
location: resourceGroup().location
sku: {
name: 'F1'
capacity: 1
}
}
resource webApplication 'Microsoft.Web/sites@2018-11-01' = {
name: 'name'
location: resourceGroup().location
properties: {
serverFarmId: appServicePlan.id
}
}
Next steps
For more information about the linter, see Use Bicep linter.
Povratne informacije
Pošalјite i prikažite povratne informacije za