|
2 | 2 | title: Define multiple instances of a property
|
3 | 3 | description: Use copy operation in an Azure Resource Manager template to iterate multiple times when creating a property on a resource.
|
4 | 4 | ms.topic: conceptual
|
5 |
| -ms.date: 04/08/2020 |
| 5 | +ms.date: 04/14/2020 |
6 | 6 | ---
|
7 | 7 | # Property iteration in ARM templates
|
8 | 8 |
|
@@ -107,7 +107,63 @@ Resource Manager expands the `copy` array during deployment. The name of the arr
|
107 | 107 |
|
108 | 108 | 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.
|
109 | 109 |
|
| 110 | +The following example template creates a failover group for databases that are passed in as an array. |
110 | 111 |
|
| 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 | +``` |
111 | 167 |
|
112 | 168 | The copy element is an array so you can specify more than one property for the resource.
|
113 | 169 |
|
|
0 commit comments