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

The template reference 'identities1Res' is not valid: #15515

Open
slavizh opened this issue Nov 7, 2024 · 3 comments
Open

The template reference 'identities1Res' is not valid: #15515

slavizh opened this issue Nov 7, 2024 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@slavizh
Copy link
Contributor

slavizh commented Nov 7, 2024

Bicep version
Bicep CLI version 0.31.34 (ec82b47)

Describe the bug
I get error:

Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template reference 'identities1Res' is not valid: could not find template resource or resource copy with this name. Please see https://aka.ms/arm-function-reference for usage details.'.

in some specific scenario.

This is related to #13674

To Reproduce
To reproduce:

targetScope = 'subscription'

param identities1 array = [
  {
    id: 'Id2'
    type: 'id'
  }
]

param identities2 array = [
  {
    id: 'Id3'
    type: 'id'
  }
]

resource identities1Res 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-07-31-preview' existing = [for (identity1, i) in identities1: if (identity1.type =~ 'user') {
  name: identity1.name
  scope: resourceGroup(identity1.subscriptionId, identity1.resourceGroup)
}]

resource identities2Res 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-07-31-preview' existing = [for (identity2, i) in identities2: if (identity2.type =~ 'user') {
  name: identity2.name
  scope: resourceGroup(identity2.subscriptionId, identity2.resourceGroup)
}]

module test1 'test1.bicep' = [for (item, index) in identities1: {
  name: 'test1-${index}'
  params: {
    identities: [for (identity1, i) in identities1: {
  id: identity1.type =~ 'user' ? identities1Res[i].properties.principalId : identity1.id
}]
  }
}]

module test12 'test1.bicep' = [for (item, index) in identities1: {
  name: 'test2-${index}'
  params: {
    identities: [for (identity2, i) in identities2: {
  id: identity2.type =~ 'user' ? identities2Res[i].properties.principalId : identity2.id
}]
  }
}]

output identities1 array = [for (identity1, i) in identities1: {
  id: identity1.type =~ 'user' ? identities1Res[i].properties.principalId : identity1.id
}]

output identities2 array = [for (identity2, i) in identities2: {
  id: identity2.type =~ 'user' ? identities2Res[i].properties.principalId : identity2.id
}]

test1.bicep

targetScope = 'subscription'
param identities array

Note that if you remove the two module references and leave the output which has the same value as the input for the modules the error does not appear which is strange.

bicepconfig used

"experimentalFeaturesEnabled": {
        "extensibility": true
    }

Template works fine if extensibility is not enabled.

Additional context
Add any other context about the problem here.

@slavizh
Copy link
Contributor Author

slavizh commented Nov 7, 2024

//cc @jeskew

@jeskew
Copy link
Contributor

jeskew commented Nov 7, 2024

@slavizh was this template deploying with Bicep v0.30 and then broke with v0.31? The compiled template seems to be the same across both Bicep versions, so I'm wondering if this was caused by a backend change:

Image

@slavizh
Copy link
Contributor Author

slavizh commented Nov 8, 2024

@jeskew This particular template I have not tested with the previous release as I have build the template in order to reproduce the issue and provide a simpler easier way to test it. Overall the original that this is based on I am pretty sure it was working at some point as I have tested many different scenarios. For sure there is some bug if it acts differently if you input the same code to module and if the same code is only in output.

@stephaniezyen stephaniezyen added this to the v0.32 milestone Nov 13, 2024
@stephaniezyen stephaniezyen added the bug Something isn't working label Nov 13, 2024
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