Skip to content

Commit dc3e829

Browse files
committed
improve the loop description for creating resources and modules
1 parent f2bb064 commit dc3e829

File tree

1 file changed

+6
-4
lines changed
  • articles/azure-resource-manager/bicep

1 file changed

+6
-4
lines changed

articles/azure-resource-manager/bicep/loops.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
title: Iterative loops in Bicep
33
description: Use loops to iterate over collections in Bicep
44
ms.topic: conceptual
5-
ms.date: 12/02/2021
5+
ms.date: 11/09/2022
66
---
77

88
# Iterative loops in Bicep
99

1010
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).
1111

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+
1214
### Training resources
1315

1416
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): {
132134

133135
## Array elements
134136

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.
136138

137139
```bicep
138140
param location string = resourceGroup().location
@@ -152,7 +154,7 @@ resource storageAcct 'Microsoft.Storage/storageAccounts@2021-06-01' = [for name
152154
}]
153155
```
154156

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.
156158

157159
::: code language="bicep" source="~/azure-docs-bicep-samples/samples/loops/loopproperty.bicep" highlight="23-28" :::
158160

@@ -208,7 +210,7 @@ output deployedNSGs array = [for (name, i) in orgNames: {
208210

209211
## Dictionary object
210212

211-
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.
212214

213215
```bicep
214216
param nsgValues object = {

0 commit comments

Comments
 (0)