Resource Group Scoped Deployments
Azure Developer CLI (azd
) supports deployments at both the subscription and resource group scopes. By default, azd
creates a resource group that contains the provisioned resources in the subscription you choose during the azd up
workflow. However, azd
also allows you to deploy to an existing resource group. When you choose an existing resource group, the scope of permissions needed to run azd provision
is reduced from subscription level to the resource group level.
In this article, you learn how to modify templates to enable resource group scoped deployments.
Note
Resource Group Scoped Deployment is currently a beta feature. Learn more about our versioning strategy.
Modify the target scope of a template
In
main.bicep
file of yourazd
template, changetargetScope
:targetScope = 'resourceGroup'
Remove
scope: rg
from all the module references inmain.bicep
.Use resource group instead of subscription when you create a unique resource token in
main.bicep
, .var resourceToken = toLower(uniqueString(resourceGroup().id, environmentName, location))
Remove the following section of code in
main.bicep
that organizes resources into a resource group.// Organize resources in a resource group resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}' location: location tags: tags }
If applicable, in the
.azdo\pipelines\azure-dev.yml
and.github\workflows\azure-dev.yml
files, add the Azure resource group environment variable to your tasks.AZURE_RESOURCE_GROUP: $(AZURE_RESOURCE_GROUP)
Note
For an example of these changes applied to the React Web App with Node.js API and MongoDB on Azure template, see this GitHub comparison.
To set the resource group to deploy to manually, you can set AZURE_RESOURCE_GROUP
in your environment. Learn more about that here.
Alternatively, if you do not have a resource group specified in your environment, azd
prompts you to pick an existing resource group from your subscription or create a new one when you run azd provision
.