|
2 | 2 | title: Deploy resources cross subscription & resource group
|
3 | 3 | description: Shows how to target more than one Azure subscription and resource group during deployment.
|
4 | 4 | ms.topic: conceptual
|
5 |
| -ms.date: 12/09/2019 |
| 5 | +ms.date: 05/18/2020 |
6 | 6 | ---
|
7 | 7 |
|
8 |
| -# Deploy Azure resources to more than one subscription or resource group |
| 8 | +# Deploy Azure resources across subscriptions or resource groups |
9 | 9 |
|
10 |
| -Typically, you deploy all the resources in your template to a single [resource group](../management/overview.md). However, there are scenarios where you want to deploy a set of resources together but place them in different resource groups or subscriptions. For example, you may want to deploy the backup virtual machine for Azure Site Recovery to a separate resource group and location. Resource Manager enables you to use nested templates to target more than one subscription and resource group. |
| 10 | +Resource Manager enables you to deploy to more than one resource group in a single deployment. You use nested templates to specify resource groups that are different than the resource group in the deployment operation. The resource groups can exist in different subscriptions. |
11 | 11 |
|
12 | 12 | > [!NOTE]
|
13 |
| -> You can deploy to only five resource groups in a single deployment. Typically, this limitation means you can deploy to one resource group specified for the parent template, and up to four resource groups in nested or linked deployments. However, if your parent template contains only nested or linked templates and does not itself deploy any resources, then you can include up to five resource groups in nested or linked deployments. |
| 13 | +> You can deploy to **800 resource groups** in a single deployment. Typically, this limitation means you can deploy to one resource group specified for the parent template, and up to 799 resource groups in nested or linked deployments. However, if your parent template contains only nested or linked templates and does not itself deploy any resources, then you can include up to 800 resource groups in nested or linked deployments. |
14 | 14 |
|
15 | 15 | ## Specify subscription and resource group
|
16 | 16 |
|
17 |
| -To target a different resource group or subscription, use a [nested or linked template](linked-templates.md). The `Microsoft.Resources/deployments` resource type provides parameters for `subscriptionId` and `resourceGroup`, which enable you to specify the subscription and resource group for the nested deployment. If you don't specify the subscription ID or resource group, the subscription and resource group from the parent template is used. All the resource groups must exist before running the deployment. |
| 17 | +To target a resource group that is different than the one for parent template, use a [nested or linked template](linked-templates.md). Within the deployment resource type, specify values for the subscription ID and resource group that you want the nested template to deploy to. |
18 | 18 |
|
19 |
| -The account you use to deploy the template must have permissions to deploy to the specified subscription ID. If the specified subscription exists in a different Azure Active Directory tenant, you must [add guest users from another directory](../../active-directory/active-directory-b2b-what-is-azure-ad-b2b.md). |
| 19 | +:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/crosssubscription.json" range="38-43" highlight="5-6"::: |
20 | 20 |
|
21 |
| -To specify a different resource group and subscription, use: |
| 21 | +If you don't specify the subscription ID or resource group, the subscription and resource group from the parent template are used. All the resource groups must exist before running the deployment. |
22 | 22 |
|
23 |
| -```json |
24 |
| -"resources": [ |
25 |
| - { |
26 |
| - "apiVersion": "2017-05-10", |
27 |
| - "name": "nestedTemplate", |
28 |
| - "type": "Microsoft.Resources/deployments", |
29 |
| - "resourceGroup": "[parameters('secondResourceGroup')]", |
30 |
| - "subscriptionId": "[parameters('secondSubscriptionID')]", |
31 |
| - ... |
32 |
| - } |
33 |
| -] |
34 |
| -``` |
| 23 | +The account that deploys the template must have permission to deploy to the specified subscription ID. If the specified subscription exists in a different Azure Active Directory tenant, you must [add guest users from another directory](../../active-directory/active-directory-b2b-what-is-azure-ad-b2b.md). |
35 | 24 |
|
36 |
| -If your resource groups are in the same subscription, you can remove the **subscriptionId** value. |
37 |
| - |
38 |
| -The following example deploys two storage accounts. The first storage account is deployed to the resource group specified during deployment. The second storage account is deployed to the resource group specified in the `secondResourceGroup` and `secondSubscriptionID` parameters: |
39 |
| - |
40 |
| -```json |
41 |
| -{ |
42 |
| - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", |
43 |
| - "contentVersion": "1.0.0.0", |
44 |
| - "parameters": { |
45 |
| - "storagePrefix": { |
46 |
| - "type": "string", |
47 |
| - "maxLength": 11 |
48 |
| - }, |
49 |
| - "secondResourceGroup": { |
50 |
| - "type": "string" |
51 |
| - }, |
52 |
| - "secondSubscriptionID": { |
53 |
| - "type": "string", |
54 |
| - "defaultValue": "" |
55 |
| - }, |
56 |
| - "secondStorageLocation": { |
57 |
| - "type": "string", |
58 |
| - "defaultValue": "[resourceGroup().location]" |
59 |
| - } |
60 |
| - }, |
61 |
| - "variables": { |
62 |
| - "firstStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]", |
63 |
| - "secondStorageName": "[concat(parameters('storagePrefix'), uniqueString(parameters('secondSubscriptionID'), parameters('secondResourceGroup')))]" |
64 |
| - }, |
65 |
| - "resources": [ |
66 |
| - { |
67 |
| - "type": "Microsoft.Storage/storageAccounts", |
68 |
| - "apiVersion": "2017-06-01", |
69 |
| - "name": "[variables('firstStorageName')]", |
70 |
| - "location": "[resourceGroup().location]", |
71 |
| - "sku":{ |
72 |
| - "name": "Standard_LRS" |
73 |
| - }, |
74 |
| - "kind": "Storage", |
75 |
| - "properties": { |
76 |
| - } |
77 |
| - }, |
78 |
| - { |
79 |
| - "type": "Microsoft.Resources/deployments", |
80 |
| - "apiVersion": "2017-05-10", |
81 |
| - "name": "nestedTemplate", |
82 |
| - "resourceGroup": "[parameters('secondResourceGroup')]", |
83 |
| - "subscriptionId": "[parameters('secondSubscriptionID')]", |
84 |
| - "properties": { |
85 |
| - "mode": "Incremental", |
86 |
| - "template": { |
87 |
| - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", |
88 |
| - "contentVersion": "1.0.0.0", |
89 |
| - "parameters": {}, |
90 |
| - "variables": {}, |
91 |
| - "resources": [ |
92 |
| - { |
93 |
| - "type": "Microsoft.Storage/storageAccounts", |
94 |
| - "apiVersion": "2017-06-01", |
95 |
| - "name": "[variables('secondStorageName')]", |
96 |
| - "location": "[parameters('secondStorageLocation')]", |
97 |
| - "sku":{ |
98 |
| - "name": "Standard_LRS" |
99 |
| - }, |
100 |
| - "kind": "Storage", |
101 |
| - "properties": { |
102 |
| - } |
103 |
| - } |
104 |
| - ] |
105 |
| - }, |
106 |
| - "parameters": {} |
107 |
| - } |
108 |
| - } |
109 |
| - ] |
110 |
| -} |
111 |
| -``` |
| 25 | +The following example deploys two storage accounts. The first storage account is deployed to the resource group specified in the deployment operation. The second storage account is deployed to the resource group specified in the `secondResourceGroup` and `secondSubscriptionID` parameters: |
| 26 | + |
| 27 | +:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/crosssubscription.json"::: |
112 | 28 |
|
113 | 29 | If you set `resourceGroup` to the name of a resource group that doesn't exist, the deployment fails.
|
114 | 30 |
|
@@ -216,99 +132,7 @@ The following [example template](https://github.com/Azure/azure-docs-json-sample
|
216 | 132 | * nested template with inner scope
|
217 | 133 | * linked template
|
218 | 134 |
|
219 |
| -```json |
220 |
| -{ |
221 |
| - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", |
222 |
| - "contentVersion": "1.0.0.0", |
223 |
| - "parameters": {}, |
224 |
| - "variables": {}, |
225 |
| - "resources": [ |
226 |
| - { |
227 |
| - "type": "Microsoft.Resources/deployments", |
228 |
| - "apiVersion": "2017-05-10", |
229 |
| - "name": "defaultScopeTemplate", |
230 |
| - "resourceGroup": "inlineGroup", |
231 |
| - "properties": { |
232 |
| - "mode": "Incremental", |
233 |
| - "template": { |
234 |
| - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", |
235 |
| - "contentVersion": "1.0.0.0", |
236 |
| - "parameters": {}, |
237 |
| - "variables": {}, |
238 |
| - "resources": [ |
239 |
| - ], |
240 |
| - "outputs": { |
241 |
| - "resourceGroupOutput": { |
242 |
| - "type": "string", |
243 |
| - "value": "[resourceGroup().name]" |
244 |
| - } |
245 |
| - } |
246 |
| - }, |
247 |
| - "parameters": {} |
248 |
| - } |
249 |
| - }, |
250 |
| - { |
251 |
| - "type": "Microsoft.Resources/deployments", |
252 |
| - "apiVersion": "2017-05-10", |
253 |
| - "name": "innerScopeTemplate", |
254 |
| - "resourceGroup": "inlineGroup", |
255 |
| - "properties": { |
256 |
| - "expressionEvaluationOptions": { |
257 |
| - "scope": "inner" |
258 |
| - }, |
259 |
| - "mode": "Incremental", |
260 |
| - "template": { |
261 |
| - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", |
262 |
| - "contentVersion": "1.0.0.0", |
263 |
| - "parameters": {}, |
264 |
| - "variables": {}, |
265 |
| - "resources": [ |
266 |
| - ], |
267 |
| - "outputs": { |
268 |
| - "resourceGroupOutput": { |
269 |
| - "type": "string", |
270 |
| - "value": "[resourceGroup().name]" |
271 |
| - } |
272 |
| - } |
273 |
| - }, |
274 |
| - "parameters": {} |
275 |
| - } |
276 |
| - }, |
277 |
| - { |
278 |
| - "type": "Microsoft.Resources/deployments", |
279 |
| - "apiVersion": "2017-05-10", |
280 |
| - "name": "linkedTemplate", |
281 |
| - "resourceGroup": "linkedGroup", |
282 |
| - "properties": { |
283 |
| - "mode": "Incremental", |
284 |
| - "templateLink": { |
285 |
| - "contentVersion": "1.0.0.0", |
286 |
| - "uri": "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/resourceGroupName.json" |
287 |
| - }, |
288 |
| - "parameters": {} |
289 |
| - } |
290 |
| - } |
291 |
| - ], |
292 |
| - "outputs": { |
293 |
| - "parentRG": { |
294 |
| - "type": "string", |
295 |
| - "value": "[concat('Parent resource group is ', resourceGroup().name)]" |
296 |
| - }, |
297 |
| - "defaultScopeRG": { |
298 |
| - "type": "string", |
299 |
| - "value": "[concat('Default scope resource group is ', reference('defaultScopeTemplate').outputs.resourceGroupOutput.value)]" |
300 |
| - }, |
301 |
| - "innerScopeRG": { |
302 |
| - "type": "string", |
303 |
| - "value": "[concat('Inner scope resource group is ', reference('innerScopeTemplate').outputs.resourceGroupOutput.value)]" |
304 |
| - }, |
305 |
| - "linkedRG": { |
306 |
| - "type": "string", |
307 |
| - "value": "[concat('Linked resource group is ', reference('linkedTemplate').outputs.resourceGroupOutput.value)]" |
308 |
| - } |
309 |
| - } |
310 |
| -} |
311 |
| -``` |
| 135 | +:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/crossresourcegroupproperties.json"::: |
312 | 136 |
|
313 | 137 | To test the preceding template and see the results, use PowerShell or Azure CLI.
|
314 | 138 |
|
|
0 commit comments