为什么 Bicep 中不推荐 'dependsOn'?

Why is 'dependsOn' not recommended in Bicep?

Microsoft documents 隐式和显式依赖关系的目的。其中显式依赖使用 'dependsOn'。但有人提到这种方法的用例很少见。

可以对以下内容进行一些说明:

来自 MS 的例子

resource dnsZone 'Microsoft.Network/dnszones@2018-05-01' = {
  name: 'demoeZone1'
  location: 'global'
}

resource otherZone 'Microsoft.Network/dnszones@2018-05-01' = {
  name: 'demoZone2'
  location: 'global'
  dependsOn: [
    dnsZone
  ]
}

引用

You can't query which resources were defined in the dependsOn element after deployment.

假设'otherZone'是一个dependsOn元素,仍然可以使用符号名查询

我错了吗?如果是的话,the dependsOn element 是什么意思?

我的理解是,在没有充分(部署相关)理由的情况下设置那些明确的 dependsOn 元素没有任何好处,因为一旦部署完成,你就看不到任何地方(在 Azure 门户中)您在文件中设置了此依赖项。

dependsOn 的用例是,如果您需要确保资源管理器仅在创建其他资源后(而不是并行)创建具有 dependOn 的资源。

但在大多数情况下,您需要设置具有相同效果的父关系(隐式依赖)。

正如文章中所述,您 link 到:

The following example shows a DNS zone named otherZone that depends on a DNS zone named dnsZone

这意味着 otherZone 不是 dependsOn 元素,它依赖于 dnsZone

While you may be inclined to use dependsOn to map relationships between your resources, it's important to understand why you're doing it. For example, to document how resources are interconnected, dependsOn isn't the right approach. You can't query which resources were defined in the dependsOn element after deployment. Setting unnecessary dependencies slows deployment time because Resource Manager can't deploy those resources in parallel.

Bicep 自动(隐式)创建依赖关系

Azure Resource Manager evaluates the dependencies between resources, and deploys them in their dependent order. When resources aren't dependent on each other, Resource Manager deploys them in parallel.

因此在大多数情况下不需要明确设置它们。