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/loops.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,15 @@
2
2
title: Iterative loops in Bicep
3
3
description: Use loops to iterate over collections in Bicep
4
4
ms.topic: conceptual
5
-
ms.date: 12/02/2021
5
+
ms.date: 11/09/2022
6
6
---
7
7
8
8
# Iterative loops in Bicep
9
9
10
10
This article shows you how to use the `for` syntax to iterate over items in a collection. This functionality is supported starting in v0.3.1 onward. You can use loops to define multiple copies of a resource, module, variable, property, or output. Use loops to avoid repeating syntax in your Bicep file and to dynamically set the number of copies to create during deployment. To go through a quickstart, see [Quickstart: Create multiple instances](./quickstart-loops.md).
11
11
12
+
To use loops to create multiple resources or modules, each instance must have a unique value for the name property. You can use the index value or unique values in arrays or collections to create the names.
13
+
12
14
### Training resources
13
15
14
16
If you would rather learn about loops through step-by-step guidance, see [Build flexible Bicep templates by using conditions and loops](/training/modules/build-flexible-bicep-templates-conditions-loops/).
@@ -132,7 +134,7 @@ module stgModule './storageAccount.bicep' = [for i in range(0, storageCount): {
132
134
133
135
## Array elements
134
136
135
-
The following example creates one storage account for each name provided in the `storageNames` parameter.
137
+
The following example creates one storage account for each name provided in the `storageNames` parameter. Note the name property for each resource instance must be unique.
136
138
137
139
```bicep
138
140
param location string = resourceGroup().location
@@ -152,7 +154,7 @@ resource storageAcct 'Microsoft.Storage/storageAccounts@2021-06-01' = [for name
152
154
}]
153
155
```
154
156
155
-
The next example iterates over an array to define a property. It creates two subnets within a virtual network.
157
+
The next example iterates over an array to define a property. It creates two subnets within a virtual network. Note the subnet names must be unique.
To iterate over elements in a dictionary object, use the [items function](bicep-functions-object.md#items), which converts the object to an array. Use the `value` property to get properties on the objects.
213
+
To iterate over elements in a dictionary object, use the [items function](bicep-functions-object.md#items), which converts the object to an array. Use the `value` property to get properties on the objects. Note the nsg resource names must be unique.
0 commit comments