You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/diagnostics/bcp144.md
+5-7Lines changed: 5 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,13 +42,11 @@ resource demo 'Microsoft.Storage/storageAccounts@2022-09-01' = [for name in name
42
42
properties: {}
43
43
}]
44
44
45
-
// This line triggers BCP144
45
+
// ❌ This line triggers BCP144.
46
46
output storageNames array = [for r in demo: r.name]
47
47
```
48
48
49
-
To resolve BCP144, use an array index to access each specific resource in the collection. Instead of looping over the collection directly, loop over the input array and use the index to reference the corresponding item.
50
-
51
-
## Example of correct Bicep code (resource collection)
49
+
To resolve BCP144, use an array index to access each specific resource in the collection.
52
50
53
51
```bicep
54
52
param names array = [
@@ -66,7 +64,7 @@ resource demo 'Microsoft.Storage/storageAccounts@2022-09-01' = [for name in name
66
64
properties: {}
67
65
}]
68
66
69
-
// ✅ Correct usage with indexing
67
+
// ✅ Correct usage with indexing.
70
68
output storageNames array = [for (name, i) in names: demo[i].name]
71
69
```
72
70
@@ -85,7 +83,7 @@ module storageModule 'storage.bicep' = [for loc in locations: {
85
83
}
86
84
}]
87
85
88
-
// This line triggers BCP144
86
+
// ❌ This line triggers BCP144.
89
87
output moduleOutputs array = [for m in storageModule: m.outputs.storageAccountName]
90
88
```
91
89
@@ -104,7 +102,7 @@ module storageModule 'storage.bicep' = [for loc in locations: {
104
102
}
105
103
}]
106
104
107
-
// ✅ Correct usage with indexing
105
+
// ✅ Correct usage with indexing.
108
106
output moduleOutputs array = [for (loc, i) in locations: storageModule[i].outputs.storageAccountName]
0 commit comments