Subscription-scoped Bicep module emits invalid resourceGroup().location in nested deployments, causing deployment failure #18710
Replies: 1 comment
-
|
I believe the issue is that main.bicep is compiling as a resource-group scoped template. Bicep templates are resource group-scoped by default; you can override this behavior by setting Because |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When deploying resource groups using a Bicep template at the subscription scope, with a module pattern like:
Using windows-latest build agent via pipeline in Azure Devops, tried bicep build locally with same versions:
Bicep version: (your version, e.g., 0.24.24)
CLI version: (your version, e.g., 2.60.0)
OS: (your OS, e.g., Windows 11)
BICEPPARAM:
MAIN BICEP:
Running the deployment with azure cli on windows-latest build agent:
az deployment sub create --location eastus --template-file main.bicep --parameters ...
The generated ARM template for the nested deployment contains JSON:
This results in the error:
ERROR: The target scope "resourceGroup" does not match the deployment scope "subscription".
or resourceGroup().location is not valid at the subscription scope
Expected Behavior:
The Bicep compiler should emit a valid Azure region string for the location property of the nested deployment (e.g., "location": "eastus2", or from the resource group object), not resourceGroup().location.
It should be possible to specify the deployment location for each nested deployment at the subscription scope, even when using a module.
I tried setting --location 'eastus' for the deployment on the az command but get the same error
Actual Behavior:
The location property for the nested Microsoft.Resources/deployments resource is set to resourceGroup().location, which is invalid at subscription scope.
This causes deployments to fail unless the user manually builds the ARM template and patches the location property.
Steps to Reproduce:
Create a Bicep template as shown above, with a resource group module and an array of resourceGroups.
Deploy using az deployment sub create.
Observe the generated ARM template contains "location": "[resourceGroup().location]".
Deployment fails with an error.
Workaround:
Manually build the Bicep file to JSON.
Edit the generated template to set a valid Azure region for all Microsoft.Resources/deployments resources.
Deploy the JSON template instead of the Bicep file.
Related Issues:
#10151 says it was fixed in version [ 0.22.0+ ]
Azure/bicep#4967
Azure/bicep#12156
Beta Was this translation helpful? Give feedback.
All reactions