Skip to content
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

Module scope not being emitted in ARM when referencing resource via variable #10475

Open
miqm opened this issue Apr 19, 2023 · 2 comments
Open
Labels
bug Something isn't working
Milestone

Comments

@miqm
Copy link
Collaborator

miqm commented Apr 19, 2023

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

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)

@miqm miqm added the bug Something isn't working label Apr 19, 2023
@miqm miqm added this to Bicep Apr 19, 2023
@github-project-automation github-project-automation bot moved this to Todo in Bicep Apr 19, 2023
@miqm miqm added this to the v0.18 milestone Apr 19, 2023
@miqm
Copy link
Collaborator Author

miqm commented Apr 19, 2023

seems similar to #7154

@stephaniezyen stephaniezyen modified the milestones: v0.18, v0.19 May 24, 2023
@stephaniezyen stephaniezyen modified the milestones: v0.19, v0.20, v0.21 Jul 11, 2023
@anthony-c-martin anthony-c-martin modified the milestones: v0.21, v1.0 Aug 11, 2023
@anthony-c-martin anthony-c-martin removed their assignment Aug 11, 2023
@anthony-c-martin
Copy link
Member

This is going to be a pretty involved fix - ultimately we need to be able to use the IR earlier in the Bicep build process, and perform analysis + raise diagnostics as we go along.

Adding to 1.0 release for now as I'm not sure we'll be able to get to it sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants