itye1970
itye1970

Reputation: 1985

Check if a resource exists then deploy another resource using Azure Arm Template

I want to create a template that deploys a VM. However I want to create a condition to check if a virtual network exists first before deploying. Whats the best way of coding this? For example say I want to create a VM called Server01 which needs to connect to a virtual network called VNET1 in resource group RESOURCEGROUP01. Whats the best way of checking this exists first before deploying the VM using the ARM template which creates the VM Server01?

Upvotes: 3

Views: 2730

Answers (1)

4c74356b41
4c74356b41

Reputation: 72171

There is no way of doing this with ARM Template. Two remarks:

  1. you could code you template to créate\update the vnet, so it doesnt matter if it exists or not (well, unless somebody changed vnet settings, than its a problem, changes will get lost)
  2. you could wrap your template with a piece of powershell\whatever, that would determine if the resource exists, and pass in the parameter value depending on that and use a conditional statement in the template that would decide what to do based on the input (but the input has to come from elsewhere)

Upvotes: 1

Related Questions