Module scope not being emitted in ARM when referencing resource via variable
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
**Bicep version**
0.16.2
**Describe the bug**
Bicep does not report an error and allows construction as below but when compiled to ARM, module scope (`resourceGroup` property in ARM-json) is not emitted.
**To Reproduce**
```bicep
targetScope = 'subscription'
var groups = [
{
name: 'group1'
location: 'westus'
}
{
name: 'group2'
location: 'eastus'
}
]
resource rg0 'Microsoft.Resources/resourceGroups@2022-09-01' = {
name: 'group0'
location: 'centralus'
}
resource _rg 'Microsoft.Resources/resourceGroups@2022-09-01' = [for (item, index) in groups: {
name: item.name
location: item.location
}]
var rg = {
group1: _rg[0]
group2: _rg[1]
}
var x = _rg[1]
var y = rg0
module mod1 'nullmod.bicep' = {
name: 'mod1'
scope: _rg[0]
}
module mod2 'nullmod.bicep' = {
name: 'mod2'
scope: rg.group2
}
module mod3 'nullmod.bicep' = {
name: 'mod3'
scope: x
}
module mod4 'nullmod.bicep' = {
name: 'mod4'
scope: y // here is an error but it totally does not relate to why we can't do this
}
```
Only for `mod1` the property `resourceGroup` is emitted, but for others (mod2, mod3) aren't plus for mod4 there's a bicep 120 error: `This expression is being used in an assignment to the "scope" property of the "module" type, which requires a value that can be calculated at the start of the deployment. You are referencing a variable which cannot be calculated at the start ("y" -> "rg0"). Properties of rg0 which can be calculated at the start include "apiVersion", "id", "name", "type".bicep(BCP120)`
Contributor guide
Research direction
Start with the supplied Bicep reproducer and compile it to ARM JSON, comparing mod1 through mod4 and their emitted scope properties. Trace how module scope expressions passed through variables are handled, then verify that valid resource-group references emit the expected resourceGroup property while the invalid mod4 case remains diagnosed appropriately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100