Error when using dependsOn with condition in an array of resources
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
**Bicep version**
```
$ az bicep version
Bicep CLI version 0.20.4 (c9422e016d)
```
**Describe the bug**
When multiple of resources are created in an array, and all resources can be created in parallel except for the first resource in the loop, the dependsOn doesnt allow us to contitionally reference this.
```
resource rsctestvm 'Microsoft.NetworkCloud/virtualMachines@2022-12-12-preview' = [ for i in range(0,varNumVms) : {
name: varVmNames[i]
location: RG_location
extendedLocation: extendedLocation
properties: {
}
dependsOn: (i == 0 )? [] : [ rsctestvm[0] ]
}]
```
For example in the above template bicep complains about the dependsOn statement, which sets no dependancy for the first resource in the loop. But sets the first element as the dependency for the rest of the resources in the loop. The expectation is that until rsctestvm[0] (the first resource in the array) is created the rest of the VMs will wait. Then once the rsctestvm[0] is deployed, the rest of the VMs would deploy in parallel.
However I get the below error message :
`Error BCP079: This expression is referencing its own declaration, which is not allowed.`
**To Reproduce**
build the bicep template with `az bicep build`
Contributor guide
Research direction
Start with the supplied resource-loop template and run az bicep build using the reported Bicep CLI version to reproduce BCP079. Trace how conditional dependsOn expressions reference the resource array; done means the template builds and the first resource has no dependency while later resources depend on rsctestvm[0].
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, compilers, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100