why an explicit dependsOn is not supported on a resource Group? #4114
-
Scenario I am trying to load an external json file that contains some inputs regarding storage accounts and resource group. The resource group section of my input contains an input called lookup that determines whether the RG is an existing one or needs to be created as a part of the bicep code dynamically. After creating/ looking up a RG, i have to deploy the storage accounts into that RG. input.json
main.bicep
Why am i not able to put a depensdsOn on a RG ? . I am coming from terraform background , and i am able to do the exact same thing in terraform where i can create an RG dynamically , and lookup an RG by using a data block in terraform, but i make it wait until the RG creation block of code executes by putting an explicit dependsOn in the data block that looks up an RG , and then all subsequent reference to the RG is used by using the data block. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You will want to declare your template so that it's idempotent. You expect it to run the same the second time (and subsequent times) that it runs. You don't need the That way storage will always just depend on the scope of rg implicitly. Redeploying over the top of a resource group can have some impact, in that it can remove tags, so you will want to have all necessary properties of the RG in your definition. I would recommend to layer your deployments. Create a module that creates the resource groups and sets up RBAC and tags that you deploy into the subscription scope. Then use a different combination of module/s to deploy storage and other resources in the specific resource group scope. That way you don't even need to specify any scope, it will deploy (and create resources) directly in the resource group that you deployed it into. This format should scale better for code re-use. Also based on least privilege you may use a different service principal (SP) with different RBAC for the Subscription deployment, with permissions to create the RG/RBAC, than the SP that deploys within a specific resource group. |
Beta Was this translation helpful? Give feedback.
-
Hi @brwilkinson I understand what you are saying . However i have made it to work by using the following code. Setup is that i already have a RG in azure with tags, and i just want to use it . Value of lookup is true in the below code. What i cant understand is that even though i am not deploying the resource group because of the lookup condition, i was expectiing rg.name to be null or something, but strangely this works and because of this i am able to establish an implicit dependency using rg.name and i am not requiring a depends on . Can you please explain me this behavior. Please have a look at the main.bicep
input.json
|
Beta Was this translation helpful? Give feedback.
Hi @brwilkinson
I understand what you are saying . However i have made it to work by using the following code. Setup is that i already have a RG in azure with tags, and i just want to use it . Value of lookup is true in the below code. What i cant understand is that even though i am not deploying the resource group because of the lookup condition, i was expectiing rg.name to be null or something, but strangely this works and because of this i am able to establish an implicit dependency using rg.name and i am not requiring a depends on . Can you please explain me this behavior. Please have a look at the main.bicep