Skip to content

Commit d3888df

Browse files
authored
Merge pull request #302844 from mumian/0716-bcp144
Add BCP144
2 parents 63ce0e7 + f3e73f0 commit d3888df

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-2
lines changed

articles/azure-resource-manager/bicep/bicep-core-diagnostics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.custom:
77
- devx-track-bicep
88
- devx-track-arm-template
99
- build-2025
10-
ms.date: 06/19/2025
10+
ms.date: 07/16/2025
1111
---
1212

1313
# Bicep core diagnostics
@@ -152,7 +152,7 @@ If you need more information about a particular diagnostic code, select the **Fe
152152
| <a id='BCP141' />BCP141 | Error | The expression can't be used as a decorator as it isn't callable. |
153153
| <a id='BCP142' />BCP142 | Error | Property value for-expressions can't be nested. |
154154
| <a id='BCP143' />BCP143 | Error | For-expressions can't be used with properties whose names are also expressions. |
155-
| <a id='BCP144' />BCP144 | Error | Directly referencing a resource or module collection isn't currently supported here. Apply an array indexer to the expression. |
155+
| <a id='BCP144' />[BCP144](./diagnostics/bcp144.md) | Error | Directly referencing a resource or module collection isn't currently supported here. Apply an array indexer to the expression. |
156156
| <a id='BCP145' />BCP145 | Error | Output `{identifier}` is declared multiple times. Remove or rename the duplicates. |
157157
| <a id='BCP147' />[BCP147](./diagnostics/bcp147.md) | Error | Expected a parameter declaration after the decorator. |
158158
| <a id='BCP148' />BCP148 | Error | Expected a variable declaration after the decorator. |
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
title: BCP144
3+
description: Directly referencing a resource or module collection isn't currently supported here. Apply an array indexer to the expression.
4+
ms.topic: reference
5+
ms.custom: devx-track-bicep
6+
ms.date: 07/16/2025
7+
---
8+
9+
# Bicep diagnostic code - BCP144
10+
11+
This diagnostic occurs when you try to reference a resource or module collection (for example, one defined using a `for`-loop) without specifying an index. Bicep requires that such references explicitly indicate which resource or module in the collection you're referring to using an array index.
12+
13+
## Description
14+
15+
Directly referencing a resource or module collection isn't currently supported here. Apply an array indexer to the expression.
16+
17+
## Level
18+
19+
Error
20+
21+
## Solutions
22+
23+
To resolve BCP144, use an array index to access each specific resource or module in the collection. Instead of looping over the collection directly, loop over the input array and use the index to reference the corresponding item.
24+
25+
## Examples
26+
27+
The following example raises the diagnostic because it references a resource collection without specifying an index.
28+
29+
```bicep
30+
param names array = [
31+
'one'
32+
'two'
33+
]
34+
35+
resource demo 'Microsoft.Storage/storageAccounts@2022-09-01' = [for name in names: {
36+
name: 'demo${name}'
37+
location: resourceGroup().location
38+
sku: {
39+
name: 'Standard_LRS'
40+
}
41+
kind: 'StorageV2'
42+
properties: {}
43+
}]
44+
45+
// ❌ This line triggers BCP144.
46+
output storageNames array = [for r in demo: r.name]
47+
```
48+
49+
To resolve BCP144, use an array index to access each specific resource in the collection.
50+
51+
```bicep
52+
param names array = [
53+
'one'
54+
'two'
55+
]
56+
57+
resource demo 'Microsoft.Storage/storageAccounts@2022-09-01' = [for name in names: {
58+
name: 'demo${name}'
59+
location: resourceGroup().location
60+
sku: {
61+
name: 'Standard_LRS'
62+
}
63+
kind: 'StorageV2'
64+
properties: {}
65+
}]
66+
67+
// ✅ Correct usage with indexing.
68+
output storageNames array = [for (name, i) in names: demo[i].name]
69+
```
70+
71+
The following example shows the error code with a module collection.
72+
73+
```bicep
74+
param locations array = [
75+
'eastus'
76+
'westus'
77+
]
78+
79+
module storageModule 'storage.bicep' = [for loc in locations: {
80+
name: 'storage-${loc}'
81+
params: {
82+
location: loc
83+
}
84+
}]
85+
86+
// ❌ This line triggers BCP144.
87+
output moduleOutputs array = [for m in storageModule: m.outputs.storageAccountName]
88+
```
89+
90+
To resolve BCP144, use an array index to access each specific module in the collection.
91+
92+
```bicep
93+
param locations array = [
94+
'eastus'
95+
'westus'
96+
]
97+
98+
module storageModule 'storage.bicep' = [for loc in locations: {
99+
name: 'storage-${loc}'
100+
params: {
101+
location: loc
102+
}
103+
}]
104+
105+
// ✅ Correct usage with indexing.
106+
output moduleOutputs array = [for (loc, i) in locations: storageModule[i].outputs.storageAccountName]
107+
```
108+
109+
## Next steps
110+
111+
For more information about Bicep diagnostics, see [Bicep core diagnostics](../bicep-core-diagnostics.md).

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ items:
694694
href: diagnostics/bcp135.md
695695
- name: BCP139
696696
href: diagnostics/bcp139.md
697+
- name: BCP144
698+
href: diagnostics/bcp144.md
697699
- name: BCP147
698700
href: diagnostics/bcp147.md
699701
- name: BCP152

0 commit comments

Comments
 (0)