Linter 規則 - 沒有不必要的 dependsOn 專案
此規則會尋找何時將不必要的 dependsOn 專案新增至資源或模組宣告。
Linter 規則程式碼
使用 Bicep 設定檔中的下列值來自訂規則設定:
no-unnecessary-dependson
解決方案
若要減少範本中的混淆,請刪除不需要的任何 dependsOn 專案。 只要範本表示式透過符號名稱參考其他資源,而不是使用硬式編碼標識元或名稱的字串,Bicep 就會自動推斷大部分的資源相依性。
下列範例會失敗此測試,因為 appServicePlan
Bicep 會自動推斷屬性值中的serverFarmId
表示式appServicePlan.id
所隱含的 Bicep 專案(參考資源符號名稱appServicePlan
)。
param location string = resourceGroup().location
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
name: 'name'
location: location
sku: {
name: 'F1'
capacity: 1
}
}
resource webApplication 'Microsoft.Web/sites@2022-03-01' = {
name: 'name'
location: location
properties: {
serverFarmId: appServicePlan.id
}
dependsOn: [
appServicePlan
]
}
您可以移除不必要的 dependsOn 專案來修正此問題。
param location string = resourceGroup().location
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
name: 'name'
location: location
sku: {
name: 'F1'
capacity: 1
}
}
resource webApplication 'Microsoft.Web/sites@2022-03-01' = {
name: 'name'
location: location
properties: {
serverFarmId: appServicePlan.id
}
}
使用 快速修正 來移除不必要的 dependsOn 專案。
下一步
如需 Linter 的詳細資訊,請參閱使用 Bicep Linter。