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/templates/copy-resources.md
+30-32Lines changed: 30 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Deploy multiple instances of resources
3
3
description: Use copy operation and arrays in an Azure Resource Manager template (ARM template) to deploy resource type many times.
4
4
ms.topic: how-to
5
5
ms.custom: devx-track-arm-template
6
-
ms.date: 04/28/2025
6
+
ms.date: 08/05/2025
7
7
---
8
8
9
9
# Resource iteration in ARM templates
@@ -12,10 +12,10 @@ This article shows you how to create more than one instance of a resource in you
12
12
13
13
You can also use copy loop with [properties](copy-properties.md), [variables](copy-variables.md), and [outputs](copy-outputs.md).
14
14
15
-
If you need to specify whether a resource is deployed at all, see [condition element](conditional-resource-deployment.md).
15
+
If you need to specify if a resource is deployed at all, see the [condition](conditional-resource-deployment.md) element.
16
16
17
17
> [!TIP]
18
-
> We recommend [Bicep](../bicep/overview.md)because it offers the same capabilities as ARM templates and the syntax is easier to use. To learn more, see [loops](../bicep/loops.md).
18
+
> [Bicep](../bicep/overview.md)is recommended since it offers the same capabilities as ARM templates, and the syntax is easier to use. To learn more, see [loops](../bicep/loops.md).
19
19
20
20
## Syntax
21
21
@@ -32,26 +32,24 @@ Add the `copy` element to the resources section of your template to deploy multi
32
32
33
33
The `name` property is any value that identifies the loop. The `count` property specifies the number of iterations you want for the resource type.
34
34
35
-
Use the `mode` and `batchSize` properties to specify if the resources are deployed in parallel or in sequence. These properties are described in [Serial or Parallel](#serial-or-parallel).
35
+
Use the `mode` and `batchSize` properties to specify if the resources are deployed in parallel or in sequence. These properties are described in [serial or parallel](#serial-or-parallel).
36
36
37
37
## Copy limits
38
38
39
-
The count can't exceed 800.
39
+
The count can't exceed 800 or be a negative number. It can be zero if you deploy the template with a recent version of the Azure CLI, PowerShell, or REST API. Specifically, you must use:
40
40
41
-
The count can't be a negative number. It can be zero if you deploy the template with a recent version of Azure CLI, PowerShell, or REST API. Specifically, you must use:
41
+
- Azure PowerShell **2.6** or later.
42
+
- Azure CLI **2.0.74** or later.
43
+
- REST API version **2019-05-10** or later.
44
+
- API version **2019-05-10** or later for the deployment resource type during [linked deployments](linked-templates.md).
42
45
43
-
- Azure PowerShell **2.6** or later
44
-
- Azure CLI **2.0.74** or later
45
-
- REST API version **2019-05-10** or later
46
-
-[Linked deployments](linked-templates.md) must use API version **2019-05-10** or later for the deployment resource type
46
+
Earlier versions of PowerShell, CLI, and the REST API don't support zero for the count.
47
47
48
-
Earlier versions of PowerShell, CLI, and the REST API don't support zero for count.
49
-
50
-
Be careful using [complete mode deployment](deployment-modes.md) with copy loop. If you redeploy with complete mode to a resource group, any resources that aren't specified in the template after resolving the copy loop are deleted.
48
+
Be careful using [complete mode deployment](deployment-modes.md) with the copy loop. If you redeploy with complete mode to a resource group, any resources that aren't specified in the template after resolving the copy loop are deleted.
51
49
52
50
## Resource iteration
53
51
54
-
The following example creates the number of storage accounts specified in the `storageCount` parameter.
52
+
The following example creates the number of storage accounts specified in the `storageCount` parameter:
55
53
56
54
```json
57
55
{
@@ -113,7 +111,7 @@ Creates these names:
113
111
114
112
The copy operation is helpful when working with arrays because you can iterate through each element in the array. Use the `length` function on the array to specify the count for iterations, and `copyIndex` to retrieve the current index in the array.
115
113
116
-
The following example creates one storage account for each name provided in the parameter.
114
+
The following example creates one storage account for each name provided in the parameter:
117
115
118
116
```json
119
117
{
@@ -153,11 +151,11 @@ The following example creates one storage account for each name provided in the
153
151
}
154
152
```
155
153
156
-
If you want to return values from the deployed resources, you can use [copy in the outputs section](copy-outputs.md).
154
+
If you want to return values from the deployed resources, you can [use copy in the **outputs** section](copy-outputs.md).
157
155
158
156
### Use symbolic name
159
157
160
-
[Symbolic name](./resource-declaration.md#use-symbolic-name) will be assigned to resource copy loops. The loop index is zero-based. In the following example, `myStorages[1]` references the second resource in the resource loop.
158
+
[Symbolic name](./resource-declaration.md#use-symbolic-name) will be assigned to resource copy loops. The loop index is zero-based. In the following example, `myStorages[1]` references the second resource in the resource loop:
161
159
162
160
```json
163
161
{
@@ -200,7 +198,7 @@ If you want to return values from the deployed resources, you can use [copy in t
200
198
}
201
199
```
202
200
203
-
If the index is a runtime value, format the reference yourself. For example
201
+
If the index is a runtime value, format the reference yourself. For example:
204
202
205
203
```json
206
204
"outputs": {
@@ -211,17 +209,17 @@ If the index is a runtime value, format the reference yourself. For example
211
209
}
212
210
```
213
211
214
-
Symbolic names can be used in [dependsOn arrays](./resource-dependency.md#depend-on-resources-in-a-loop). If a symbolic name is for a copy loop, all resources in the loop are added as dependencies. For more information, see [Depends on resources in a loop](./resource-dependency.md#depend-on-resources-in-a-loop).
212
+
Symbolic names can be used in [dependsOn arrays](./resource-dependency.md#depend-on-resources-in-a-loop). If a symbolic name is for a copy loop, all resources in the loop are added as dependencies. For more information, see [depends-on resources in a loop](./resource-dependency.md#depend-on-resources-in-a-loop).
215
213
216
-
## Serial or Parallel
214
+
## Serial or parallel
217
215
218
-
By default, Resource Manager creates the resources in parallel. It applies no limit to the number of resources deployed in parallel, other than the total limit of 800 resources in the template. The order in which they're created isn't guaranteed.
216
+
By default, Resource Manager creates the resources in parallel. It applies no limit to the number of resources deployed in parallel other than the total limit of 800 resources in the template. The order in which they're created isn't guaranteed.
219
217
220
-
However, you may want to specify that the resources are deployed in sequence. For example, when updating a production environment, you may want to stagger the updates so only a certain number are updated at any one time.
218
+
However, you might want to specify that the resources are deployed in sequence. For example, when updating a production environment, you can stagger the updates so that only a certain number update at any one time.
221
219
222
-
To serially deploy more than one instance of a resource, set `mode` to **serial** and `batchSize` to the number of instances to deploy at a time. With serial mode, Resource Manager creates a dependency on earlier instances in the loop, so it doesn't start one batch until the previous batch completes.
220
+
To serially deploy more than one instance of a resource, set `mode` to **serial** and `batchSize` to the number of instances to deploy at a time. With serial mode, Resource Manager creates a dependency on earlier instances in the loop so that it doesn't start one batch until the previous batch completes.
223
221
224
-
The value for `batchSize` can't exceed the value for `count` in the copy element.
222
+
The value for `batchSize` can't exceed the value for `count` in the copy element:
225
223
226
224
```json
227
225
{
@@ -261,7 +259,7 @@ The `mode` property also accepts **parallel**, which is the default value.
261
259
262
260
You can't use a copy loop for a child resource. To create more than one instance of a resource that you typically define as nested within another resource, you must instead create that resource as a top-level resource. You define the relationship with the parent resource through the type and name properties.
263
261
264
-
For example, suppose you typically define a dataset as a child resource within a data factory.
262
+
For example, suppose you typically define a dataset as a child resource within a data factory:
265
263
266
264
```json
267
265
{
@@ -286,11 +284,11 @@ For example, suppose you typically define a dataset as a child resource within a
286
284
}
287
285
```
288
286
289
-
To create more than one data set, move it outside of the data factory. The dataset must be at the same level as the data factory, but it's still a child resource of the data factory. You preserve the relationship between data set and data factory through the type and name properties. Since type can no longer be inferred from its position in the template, you must provide the fully qualified type in the format: `{resource-provider-namespace}/{parent-resource-type}/{child-resource-type}`.
287
+
To create more than one dataset, move it outside of the data factory. The dataset must be at the same level as the data factory, but it's still a child resource of the data factory. The type and name properties preserve the relationship between the dataset and data factory. Since type can no longer be inferred from its position in the template, you must provide the fully qualified type in this format: `{resource-provider-namespace}/{parent-resource-type}/{child-resource-type}`.
290
288
291
-
To establish a parent/child relationship with an instance of the data factory, provide a name for the data set that includes the parent resource name. Use the format: `{parent-resource-name}/{child-resource-name}`.
289
+
To establish a parent/child relationship with an instance of the data factory, provide a name for the dataset that includes the parent resource name. Use this format: `{parent-resource-name}/{child-resource-name}`.
292
290
293
-
The following example shows the implementation.
291
+
The following example shows the implementation:
294
292
295
293
```json
296
294
"resources": [
@@ -326,11 +324,11 @@ The following examples show common scenarios for creating more than one instance
326
324
327
325
## Next steps
328
326
329
-
- To set dependencies on resources that are created in a copy loop, see [Define the order for deploying resources in ARM templates](./resource-dependency.md).
330
-
- To go through a tutorial, see [Tutorial: Create multiple resource instances with ARM templates](template-tutorial-create-multiple-instances.md).
331
-
- For a Learn module that covers resource copy, see [Manage complex cloud deployments by using advanced ARM template features](/training/modules/manage-deployments-advanced-arm-template-features/).
327
+
- To set dependencies on resources that are created in a copy loop, see how to [define the order for deploying resources in ARM templates](./resource-dependency.md).
328
+
- To go through a tutorial, see one for how to [create multiple resource instances with ARM templates](template-tutorial-create-multiple-instances.md).
329
+
- For a Microsoft Learn module that covers resource copy, see how to [manage complex cloud deployments by using advanced ARM template features](/training/modules/manage-deployments-advanced-arm-template-features/).
332
330
- For other uses of the copy loop, see:
333
331
-[Property iteration in ARM templates](copy-properties.md)
334
332
-[Variable iteration in ARM templates](copy-variables.md)
335
333
-[Output iteration in ARM templates](copy-outputs.md)
336
-
- For information about using copy with nested templates, see [Using copy](linked-templates.md#using-copy).
334
+
- For information about using copy with nested templates, see how to [use copy](linked-templates.md#use-copy).
0 commit comments