简体   繁体   English

Azure ARM 模板:DependsOn 条件语句

[英]Azure ARM Template: DependsOn conditional statement

Does anyone know if there is a way to put an inline conditional statement inside the dependsOn element?有谁知道是否有办法在dependsOn元素中放置内联条件语句? I want to put a condition in that the resource will deploy on if either nestedTemplateA exists already OR if nestedTemplateB exists already.我想设置一个条件,即如果nestedTemplateA 已经存在或者nestedTemplateB 已经存在,则资源将部署。

Any help is appreciated!任何帮助表示赞赏!

  "dependsOn": [
    "[or(nestedTemplateA, nestedTemplateB)]"
  ],

ok, first of all, you can depend on existence of something (strictly speaking), you can only depend on resource being created successfully in the same (!!) template.好的,首先,您可以依赖于某些东西的存在(严格来说),您只能依赖于在同一个 (!!) 模板中成功创建的资源。 so if your template has this structure:因此,如果您的模板具有以下结构:

resource1 - nested template
resource2 - nested template
resource3 - the one you are asking about

you just need to use this as dependsOn:你只需要使用它作为dependsOn:

"dependsOn": [
    "resource1",
    "resource2"
]

but, as your question reads: "resource will deploy on if either nestedTemplateA exists already OR if nestedTemplateB exists already."但是,正如您的问题所写:“如果nestedTemplateA 已经存在或者nestedTemplateB 已经存在,则资源将部署。” its really hard for me to be sure I'm answering the right question.我真的很难确定我在回答正确的问题。 if this is not what you are asking about, can you please comment on this answer if you need more help (and, perhaps, rephrase your question).如果这不是您要问的问题,如果您需要更多帮助(或者,重新表述您的问题),能否请您对此答案发表评论。 I'll edit this answer, cheers!我会编辑这个答案,干杯!

As of today, Azure has added support for the conditional dependsOn in Define the order for deploying resources in ARM templates截至今天,Azure 在定义在 ARM 模板中部署资源的顺序中添加了对条件依赖项的支持

This allows for the exact feature you are looking for.这允许您正在寻找的确切功能。 That is to say: You can simply add all conditional dependencies in the depondsOn array.也就是说:您可以简单地在 depondsOn 数组中添加所有条件依赖项。 Those dependencies evaluated as false will be removed.那些评估为 false 的依赖项将被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM