chew224
chew224

Reputation: 501

Azure ARM Template: DependsOn conditional statement

Does anyone know if there is a way to put an inline conditional statement inside the dependsOn element? I want to put a condition in that the resource will deploy on if either nestedTemplateA exists already OR if nestedTemplateB exists already.

Any help is appreciated!

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

Upvotes: 3

Views: 5191

Answers (3)

HeyWatchThis
HeyWatchThis

Reputation: 23463

I also could not explicitly find how to or() two dependencies within the dependsOn, however I think the plain/dumb approach below is fine too, though verbose,


[
  {
    "name": "first", 
    "dependsOn": ["nestedTemplateA"],
    "do": "something"
  },
  {
    "name": "second", 
    "dependsOn": ["nestedTemplateB"],
    "do": "something"
  },
]

At least that is what I will do in my case. And it is at least not immediately obvious to me that the accepted answer, "dependsOn": ["resource1", "resource2"], is a logical or. Would love to find the documentation for this one day.

Upvotes: 0

JaydenLiang
JaydenLiang

Reputation: 11

As of today, Azure has added support for the conditional dependsOn in Define the order for deploying resources in ARM templates

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. Those dependencies evaluated as false will be removed.

Upvotes: 1

4c74356b41
4c74356b41

Reputation: 72171

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": [
    "resource1",
    "resource2"
]

but, as your question reads: "resource will deploy on if either nestedTemplateA exists already OR if nestedTemplateB exists already." 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!

Upvotes: 5

Related Questions