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

System.NotImplementedException when using for loop and spread operator in the same resource definition #15509

Open
BalassaMarton opened this issue Nov 6, 2024 · 1 comment
Labels
bug Something isn't working Quality Sprint: Yes

Comments

@BalassaMarton
Copy link

Bicep version

> bicep version
Bicep CLI version 0.30.23 (ec3612efc7)

Describe the bug
When I try to use a for loop and the spread operator inside the same resource definition, I get this error: System.NotImplementedException: Cannot emit unexpected expression of type ForLoopExpression

To Reproduce

// Bicep-spread-test.bicep
param databaseName string
param locations string[]
param setIpRules bool = false
param ipAddresses string[]?
param addAzurePortalIPAddresses bool = false

var azurePortalIPAddresses = [
  '13.88.56.148'
  '40.91.218.243'
  '13.91.105.215'
  '4.210.172.107'
]

var allIpAddresses = union((ipAddresses ?? []), addAzurePortalIPAddresses ? azurePortalIPAddresses : [])

var ipRules = setIpRules ? { ipRules: map(allIpAddresses, ip => { ipAddressOrRange: ip }) } : {}

resource database 'Microsoft.DocumentDB/databaseAccounts@2024-05-15' = {
  name: databaseName
  location: 'westus'
  kind: 'GlobalDocumentDB'
  properties: {
    databaseAccountOfferType: 'Standard'
    locations: [ for (location, idx) in locations: { locationName: location, failoverPriority: idx } ]
    ...ipRules
  }
}
az bicep build --stdout --file ./Bicep-spread-test.bicep

The error goes away if I extract the for loop in a variable, or remove usages of the spread operator.

@jeskew
Copy link
Contributor

jeskew commented Nov 6, 2024

This may require #14106 to fully address. ARM copy properties (what for loops compile to) can't be used inside of a shallowMerge function (what spread operations compile to), so the loop would need to be translated to a map function expression for this work

@stephaniezyen stephaniezyen added bug Something isn't working Quality Sprint: Yes and removed Needs: Triage 🔍 labels Nov 6, 2024
@stephaniezyen stephaniezyen added this to the Committed Backlog milestone Nov 6, 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 Quality Sprint: Yes
Projects
Status: Todo
Development

No branches or pull requests

3 participants