Skip to content

Commit 2f57555

Browse files
committed
add property copy array example
1 parent a200bfc commit 2f57555

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Define multiple instances of a property
33
description: Use copy operation in an Azure Resource Manager template to iterate multiple times when creating a property on a resource.
44
ms.topic: conceptual
5-
ms.date: 04/08/2020
5+
ms.date: 04/14/2020
66
---
77
# Property iteration in ARM templates
88

@@ -107,7 +107,63 @@ Resource Manager expands the `copy` array during deployment. The name of the arr
107107

108108
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.
109109

110+
The following example template creates a failover group for databases that are passed in as an array.
110111

112+
```json
113+
{
114+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
115+
"contentVersion": "1.0.0.0",
116+
"parameters": {
117+
"primaryServerName": {
118+
"type": "string"
119+
},
120+
"secondaryServerName": {
121+
"type": "string"
122+
},
123+
"databaseNames": {
124+
"type": "array",
125+
"defaultValue": [
126+
"mydb1",
127+
"mydb2",
128+
"mydb3"
129+
]
130+
}
131+
},
132+
"variables": {
133+
"failoverName": "[concat(parameters('primaryServerName'),'/', parameters('primaryServerName'),'failovergroups')]"
134+
},
135+
"resources": [
136+
{
137+
"type": "Microsoft.Sql/servers/failoverGroups",
138+
"apiVersion": "2015-05-01-preview",
139+
"name": "[variables('failoverName')]",
140+
"properties": {
141+
"readWriteEndpoint": {
142+
"failoverPolicy": "Automatic",
143+
"failoverWithDataLossGracePeriodMinutes": 60
144+
},
145+
"readOnlyEndpoint": {
146+
"failoverPolicy": "Disabled"
147+
},
148+
"partnerServers": [
149+
{
150+
"id": "[resourceId('Microsoft.Sql/servers', parameters('secondaryServerName'))]"
151+
}
152+
],
153+
"copy": [
154+
{
155+
"name": "databases",
156+
"count": "[length(parameters('databaseNames'))]",
157+
"input": "[resourceId('Microsoft.Sql/servers/databases', parameters('primaryServerName'), parameters('databaseNames')[copyIndex('databases')])]"
158+
}
159+
]
160+
}
161+
}
162+
],
163+
"outputs": {
164+
}
165+
}
166+
```
111167

112168
The copy element is an array so you can specify more than one property for the resource.
113169

0 commit comments

Comments
 (0)