-
Notifications
You must be signed in to change notification settings - Fork 762
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
copyIndex error "The provided copy name '' doesn't exist in the resource" when using triple FOR-loops for the same array #4453
Comments
Btw, found the following workaround to be valid:
|
+1 |
here is the simple (standalone) repro for this... removing any complexity of the agentPools or AKS.
var agentPools = [
{
name: 'NodePool1'
virtualNetwork: {
virtualNetworkName: 'vnet1'
subnetName: 'subnet1'
}
}
]
resource virtualNetworks 'Microsoft.Network/virtualNetworks@2021-02-01' existing = [for agentPool in agentPools: {
name: agentPool.virtualNetwork.virtualNetworkName
}]
resource subnets 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' existing = [for (agentPool, index) in agentPools: {
name: agentPool.virtualNetwork.subnetName
parent: virtualNetworks[index]
}]
var agentPoolProfiles = [for (agentPool, index) in agentPools: {
name: agentPool.name
vnetSubnetID: subnets[index].id
}]
output agentPoolProfiles array = agentPoolProfiles Expected compiled: "vnetSubnetID": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('agentPools')[copyIndex('agentPoolProfiles')].virtualNetwork.virtualNetworkName, variables('agentPools')[copyIndex('agentPoolProfiles')].virtualNetwork.subnetName)]" Actually compiled: "vnetSubnetID": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('agentPools')[copyIndex()].virtualNetwork.virtualNetworkName, variables('agentPools')[copyIndex('agentPoolProfiles')].virtualNetwork.subnetName)]" |
Thanks for the self-contained repro @brwilkinson. It looks like the root cause is that we're not doing index replacement in a way that preserves the local loop name. |
what is the status of this? I'm facing this issue as well. |
very annoying bug that for me shouldn't be hard to fix. It quite common among many resources as in many cases you have to reference subnet IDs |
Yes, we're not picking up the index expression from the parent property which fails an assertion in loop code generation. I'm working on the fix. |
+1 |
@majastrz was anything done in recent versions of Bicep to fix this? When I use the latest sample for reproduction and generate the ARM template it seems that copyIndex() has parameter now so it seems fixed. I am yet to test it with actual deployment but if the ARM code is correct there should not be a problem. |
I think @jeskew made a change that fixed loop codegen with indexed scopes. I will double check. |
I have done some tests and they show that it is fixed now. |
Thanks for confirming. I will also add your repro as a test case, so it doesn't regress in the future. |
Closing since it appears this is resolved. |
Hello, I am reproducing a very issue today with Bicep CLI version 0.28.1 I define variables with the objects for the private endpoints that the AVM modules require. The "subnetResourceId" property adequately takes the Attaching reproduction files. Bicep:
Expected:
Actual:
|
Update: it seems my issue stemps from using fixed values for the private DNS zone names. The copyIndex('...') value is not populate when I do not reference the objects of the iterated array in the name. This does not work:
This works:
|
Bicep version
0.4.63
Describe the bug
When you are using in a variable with FOR-loop a copyIndex to refer to a certain child resource reference in another FOR-loop for the same array of objects which also uses an index to retrieve its parent that is also in another FOR-loop for the same set of objects, then in the autogenerated ARM template, all the translated copyIndexes for the parent in the copy variable get blanked out.
To Reproduce
Deploy AKS Cluster with the following code for agent pool profiles. For example purpose, only 'name' and the here relevant property 'vnetSubnetID' are listed. The properties of both the resource references and of the variable 'agentPoolProfiles' are all populated using the same array [for agentPool in aksCluster.agentPools].
When deploying, this generates error:
When examining the autogenerated ARM template, the cause is clear: in the variable, the copyIndex() where a property of the parent resource is called, is always empty. It should be copyIndex('agentPoolProfiles').
Additional context
N/A
The text was updated successfully, but these errors were encountered: