-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to access resource group location through resource group scope as variable #947
Comments
I think the issue is that the Great find! |
I don't think this is the case. resourceGroup function exists in ARM, but it can be used in resource group deployments only, see: https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-resource?tabs=json#resourcegroup Banning (throw and error) using this function in modules that don't target resource group is covered in #808 and potentially connects with #774 Although for this case, we can simply use:
|
@miqm - That absolutely wont work for my use case. We deploy the same ARM template to multiple regions, but some resources (Cosmos DB for example) only need to be deployed to our designated primary region, which we check through a condition in the ARM template (and hopefully now through Bicep as it looks like conditions have been implemented). So we can't hardcode the We can continue to do this in Bicep without setting the scope to |
You will not be able to create cosmosdb in module that targets subscription - this compiles to subscription deployment where only subset of resources are valid. When you do deployment to the resource group (module with You can have a subscription module to create resourceGroups and then include resource group modules:
group.bicep
Plus: |
@miqm - Apologies, I read your previous reply as you suggesting I hardcode the location of resources, whereas your example was actually showing the resource group. What you are suggesting would probably work in most cases, however there is one (admittedly edge) case that I've come across where I still need to use I assign RBAC roles to a Cosmos DB account to allow Function App to do certain things. Because the Cosmos DB account is only in our designated primary region (UK South), the deployments for the module in every region (UK South, UK West, North Europe, etc.) are run in the same resource group (and potentially at the same time), so need unique names. Currently I append the resource group location, but using the example below would result in the Bicep ARM template In short, this is a nice to have and would probably make our lives a little easier, but it's not a deal breaker. |
So basically your problem is not related to bicep. Using 'runtime' values in resource names is forbidden in ARM, and warning on this it's covered by #360. But still - in subscription deployment you cannot use resourceGroup() function - even in ARM - this is reserved for resource group deployments only:
|
Adding internal tracking item (won't be visible to non-msft internal): https://msazure.visualstudio.com/One/_workitems/edit/8866613 |
@stephaniezyen is there any update? |
Bicep version
Bicep CLI version 0.2.14 (0a0f974)
Describe the bug
When setting
targetScope = 'subscription'
I am unable to access the location of a resource group.To Reproduce
Additional context
Before the use of
targetScope = 'subscription'
I was able to useresourceGroup().location
to access the resource group location. I understand why that wouldn't work when the Bicep file is scoped to a subscription, but I was expecting to be able to use the resource group scope variable that I set (resourceGroupScope
) to access the location.The text was updated successfully, but these errors were encountered: