Problem
I’m not sure whether it’s doable, but I’m trying to make a virtual network out of one virtualNetwork.main.bicep file and then a subnet out of another subnet.main.bicep file within the virtual network. Now I can do it, but the problem is that if I repeat the virtual network virtualNetwork.main.bicep, any subnets formed by the subnet.main.bicep file will be removed.
I realize I could just add all subnets to virtualNetwork.main.bicep, but the point is that I can delegate subnet creation to others while retaining a centralized networking setup.
Is there any way to prevent the virtual network file from overwriting what’s already there?
I hope this is clear.
Cheers
Asked by TommyAutoMagically
Solution #1
Checking to see if a resource already exists is an ask in Bicep that isn’t yet implemented.
Furthermore, you want to build a virtual network out of many modules, and I’m afraid you’ll be disappointed there as well, as that isn’t actually supported according to the debate here. Here’s what the advice suggests:
Unfortunately, this means that, in order to work around the API limitations, you’ll have to construct all of the subnets at once. Sorry!
Answered by Whit Waldo
Post is based on https://stackoverflow.com/questions/69233552/azure-bicep-deploy-if-doesnt-already-exist