'Azure BICEP deploy if doesn't already exist

I'm not sure if this is possible, but what I'm trying to do is create a virtual network from one virtualNetwork.main.bicep file and then create a subnet from another subnet.main.bicep within the virtual network. Now I can do this, but the problem I have is if I rerun the virtual network virtualNetwork.main.bicep it will remove any subnets that have been created by the subnet.main.bicep file

I know I can just add all subnets to the virtualNetwork.main.bicep but the idea is that I can hand over the creation of subnets to other people whilst maintaining a global networking configuration.

So is there any way that I can only stop the virtual network file from deleting what's already there?

Hope this makes sense.

Cheers



Solution 1:[1]

Checking to see if a resource already exists is an ask in Bicep that isn't yet implemented.

Further, you're looking at creating a virtual network from multiple modules and I fear you're going to be disappointed there as well, as that's not really supported per the discussion here. The guidance provided here suggests:

It is instead recommended to create all the subnets in the array property inside of the vnet

And unfortunately this suggests that you have to create all the subnets at once to accommodate the API shortcomings. Sorry!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Whit Waldo