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/bicep/deploy-to-resource-group.md
+37-39Lines changed: 37 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,28 @@
1
1
---
2
2
title: Use Bicep to deploy resources to resource groups
3
-
description: Describes how to deploy resources in a Bicep file. It shows how to target more than one resource group.
3
+
description: Learn how to deploy resources in a Bicep file and how to target more than one resource group.
4
4
ms.topic: how-to
5
5
ms.custom: devx-track-bicep
6
-
ms.date: 02/10/2025
6
+
ms.date: 03/25/2025
7
7
---
8
8
9
-
# Resource group deployments with Bicep files
9
+
# Use Bicep to deploy resources to resource groups
10
10
11
11
This article describes how to set scope with Bicep when deploying to a resource group. For more information, see [Understand scope](../management/overview.md#understand-scope).
12
12
13
13
## Supported resources
14
14
15
-
Most resources can be deployed to a resource group. For a list of available resources, see [ARM template reference](/azure/templates).
15
+
Most resources can be deployed to a resource group. For a list of available resources, reference the guidance for [ARM templates](/azure/templates).
16
16
17
17
## Set scope
18
18
19
-
By default, a Bicep file is scoped to the resource group. If you want to explicitly set the scope, use:
19
+
A Bicep file is scoped to the resource group by default. If you want to explicitly set the scope, use:
20
20
21
21
```bicep
22
22
targetScope = 'resourceGroup'
23
23
```
24
24
25
-
But, setting the target scope to resource group is unnecessary because that scope is used by default.
25
+
However, setting the target scope to resource group isn't necessary because that scope is used by default.
26
26
27
27
## Deployment commands
28
28
@@ -40,7 +40,7 @@ az deployment group create \
40
40
--parameters storageAccountType=Standard_GRS
41
41
```
42
42
43
-
# [PowerShell](#tab/azure-powershell)
43
+
# [Azure PowerShell](#tab/azure-powershell)
44
44
45
45
For the PowerShell deployment command, use [New-AzResourceGroupDeployment](/powershell/module/az.resources/new-azresourcegroupdeployment). The following example deploys a template to create a resource group. The resource group you specify in the `-ResourceGroupName` parameter is the **target resource group**.
For more detailed information about deployment commands and options for deploying ARM templates, see:
57
+
For more information about deployment commands and options for deploying ARM templates, see:
58
58
59
-
*[Deploy resources with ARMtemplates and Azure CLI](deploy-cli.md)
60
-
*[Deploy resources with ARM templates and Azure PowerShell](deploy-powershell.md)
61
-
*[Deploy ARM templates from Cloud Shell](deploy-cloud-shell.md)
59
+
-[How to use Azure Resource Manager (ARM) deployment templates with Azure CLI](deploy-cli.md)
60
+
-[Deploy resources with ARM templates and Azure PowerShell](deploy-powershell.md)
61
+
-[Deploy ARM templates from Cloud Shell](deploy-cloud-shell.md)
62
62
63
63
## Deployment scopes
64
64
65
65
In a Bicep file, all resources declared with the [`resource`](./resource-declaration.md) keyword must be deployed at the same scope as the deployment. For a resource group deployment, this means all `resource` declarations in the Bicep file must be deployed to the same resource group or as a child or extension resource of a resource in the same resource group as the deployment.
66
66
67
67
However, this restriction doesn't apply to [`existing`](./existing-resource.md) resources. You can reference existing resources at a different scope than the deployment.
68
68
69
-
To deploy resources at multiple scopes within a single deployment, use [modules](./modules.md). Deploying a module triggers a "nested deployment," allowing you to target different scopes. The user deploying the parent Bicep file must have the necessary permissions to initiate deployments at those scopes.
69
+
To deploy resources at multiple scopes within a single deployment, use [modules](./modules.md). Deploying a module triggers a nested deployment, allowing you to target different scopes. The user deploying the parent Bicep file must have the necessary permissions to initiate deployments at those scopes.
70
70
71
-
You can deploy a resource from within a resource-groupscope Bicep file at the following scopes:
71
+
You can deploy a resource from within a resource-group-scope Bicep file at the following scopes:
72
72
73
-
*[The same resource group](#scope-to-target-resource-group)
74
-
*[Other resource groups in the same subscription](#scope-to-different-resource-group)
75
-
*[Other resource groups in other subscriptions](#scope-to-different-resource-group)
76
-
*[The subscription](#scope-to-subscription)
77
-
*[The tenant](#scope-to-tenant)
73
+
-[The same resource group](#scope-to-target-resource-group)
74
+
-[Other resource groups in the same subscription](#scope-to-different-resource-group)
75
+
-[Other resource groups in other subscriptions](#scope-to-different-resource-group)
76
+
-[The subscription](#scope-to-subscription)
77
+
-[The tenant](#scope-to-tenant)
78
78
79
79
### Scope to target resource group
80
80
@@ -91,11 +91,11 @@ For an example template, see [Deploy to target resource group](#deploy-to-target
91
91
92
92
### Scope to different resource group
93
93
94
-
To deploy resources to a resource group that isn't the target resource group, add a [module](modules.md). Use the [resourceGroup function](bicep-functions-scope.md#resourcegroup) to set the `scope` property for that module.
94
+
To deploy resources to a resource group that isn't the target resource group, add a [module](modules.md). Use the [`resourceGroup` function](bicep-functions-scope.md#resourcegroup) to set the `scope` property for that module.
95
95
96
-
If the resource group is in a different subscription, provide the subscription ID and the name of the resource group. If the resource group is in the same subscription as the current deployment, provide only the name of the resource group. If you don't specify a subscription in the [resourceGroup function](bicep-functions-scope.md#resourcegroup), the current subscription is used.
96
+
If the resource group is in a different subscription, provide the subscription ID and the name of the resource group. If the resource group is in the same subscription as the current deployment, provide only the name of the resource group. If you don't specify a subscription in the `resourceGroup` function, the current subscription is used.
97
97
98
-
The following example shows a module that targets a resource group in a different subscription.
98
+
The following example shows a module that targets a resource group in a different subscription:
For an example template, see [Deploy to multiple resource groups](#deploy-to-multiple-resource-groups).
124
124
125
125
### Scope to subscription
126
+
`
127
+
To deploy resources to a subscription, add a module. Use the [`subscription` function](bicep-functions-scope.md#subscription) to set its `scope` property.
126
128
127
-
To deploy resources to a subscription, add a module. Use the [subscription function](bicep-functions-scope.md#subscription) to set its `scope` property.
128
-
129
-
To deploy to the current subscription, use the subscription function without a parameter.
129
+
To deploy to the current subscription, use the `subscription` function without a parameter.
Instead of using a module, you can set the scope to `tenant()` for some resource types. The following example deploys a management group at the tenant.
168
+
Instead of using a module, you can set the scope to `tenant()` for some resource types. The following example deploys a management group at the tenant:
@@ -186,7 +184,7 @@ For more information, see [Management group](deploy-to-management-group.md#manag
186
184
187
185
## Deploy to target resource group
188
186
189
-
To deploy resources in the target resource group, define those resources in the `resources` section of the template. The following template creates a storage account in the resource group that is specified in the deployment operation.
187
+
To deploy resources in the target resource group, define those resources in the `resources` section of the template. The following template creates a storage account in the resource group that's specified in the deployment operation:
You can deploy to more than one resource group in a single Bicep file.
227
+
You can deploy to more than one resource group in one Bicep file.
230
228
231
229
> [!NOTE]
232
-
> 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 doesn't itself deploy any resources, then you can include up to 800 resource groups in nested or linked deployments.
230
+
> You can deploy up to **800 resource groups** in one 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 doesn't itself deploy any resources, then you can include up to 800 resource groups in nested or linked deployments.
233
231
234
232
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:
0 commit comments