Skip to content

Commit da4c18a

Browse files
Merge pull request #248038 from mumian/0809-symbolic
Use symbolic name and languageVersion 2.0
2 parents 1cb80d4 + 162f7bb commit da4c18a

14 files changed

+1372
-145
lines changed

articles/azure-resource-manager/templates/copy-resources.md

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Deploy multiple instances of resources
33
description: Use copy operation and arrays in an Azure Resource Manager template (ARM template) to deploy resource type many times.
44
ms.topic: conceptual
55
ms.custom: devx-track-arm-template
6-
ms.date: 05/22/2023
6+
ms.date: 08/30/2023
77
---
88

99
# Resource iteration in ARM templates
@@ -91,7 +91,7 @@ The following example creates the number of storage accounts specified in the `s
9191
Notice that the name of each resource includes the `copyIndex()` function, which returns the current iteration in the loop. `copyIndex()` is zero-based. So, the following example:
9292

9393
```json
94-
"name": "[concat('storage', copyIndex())]",
94+
"name": "[format('storage{0}', copyIndex())]",
9595
```
9696

9797
Creates these names:
@@ -103,7 +103,7 @@ Creates these names:
103103
To offset the index value, you can pass a value in the `copyIndex()` function. The number of iterations is still specified in the copy element, but the value of `copyIndex` is offset by the specified value. So, the following example:
104104

105105
```json
106-
"name": "[concat('storage', copyIndex(1))]",
106+
"name": "[format('storage{0}', copyIndex(1))]",
107107
```
108108

109109
Creates these names:
@@ -156,6 +156,64 @@ The following example creates one storage account for each name provided in the
156156

157157
If you want to return values from the deployed resources, you can use [copy in the outputs section](copy-outputs.md).
158158

159+
### Use symbolic name
160+
161+
[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.
162+
163+
```json
164+
{
165+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
166+
"languageVersion": "2.0",
167+
"contentVersion": "1.0.0.0",
168+
"parameters": {
169+
"location": {
170+
"type": "string",
171+
"defaultValue": "[resourceGroup().location]"
172+
},
173+
"storageCount": {
174+
"type": "int",
175+
"defaultValue": 2
176+
}
177+
},
178+
"resources": {
179+
"myStorages": {
180+
"type": "Microsoft.Storage/storageAccounts",
181+
"apiVersion": "2022-09-01",
182+
"name": "[format('{0}storage{1}', copyIndex(), uniqueString(resourceGroup().id))]",
183+
"location": "[parameters('location')]",
184+
"sku": {
185+
"name": "Standard_LRS"
186+
},
187+
"kind": "Storage",
188+
"properties": {},
189+
"copy": {
190+
"name": "storagecopy",
191+
"count": "[parameters('storageCount')]"
192+
}
193+
}
194+
},
195+
"outputs": {
196+
"storageEndpoint":{
197+
"type": "object",
198+
"value": "[reference('myStorages[1]').primaryEndpoints]"
199+
}
200+
}
201+
}
202+
```
203+
204+
If the index is a runtime value, format the reference yourself. For example
205+
206+
```json
207+
"outputs": {
208+
"storageEndpoint":{
209+
"type": "object",
210+
"value": "[reference(format('myStorages[{0}]', variables('runtimeIndex'))).primaryEndpoints]"
211+
}
212+
}
213+
```
214+
215+
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).
216+
159217
## Serial or Parallel
160218

161219
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.
@@ -244,7 +302,7 @@ The following example shows the implementation.
244302
},
245303
{
246304
"type": "Microsoft.DataFactory/factories/datasets",
247-
"name": "[concat('exampleDataFactory', '/', 'exampleDataSet', copyIndex())]",
305+
"name": "[format('exampleDataFactory/exampleDataSet{0}', copyIndex())]",
248306
"dependsOn": [
249307
"exampleDataFactory"
250308
],

0 commit comments

Comments
 (0)