Azure CLI Resource Groups
Resource groups are logical containers that hold related Azure resources for a solution. You can use resource groups to deploy, manage, and monitor all the resources for your solution as a single entity.
Key Concepts
- Logical Organization: Resource groups allow you to group resources that share a common lifecycle, management, or billing context.
- Deployment & Management: Resources within a group can be deployed, updated, and deleted together.
- Access Control: Role-Based Access Control (RBAC) can be applied at the resource group level, simplifying permission management.
- Region: A resource group has a location. This is the location where the metadata for the resource group is stored. However, resources within the resource group can be deployed in different regions.
Common Azure CLI Commands for Resource Groups
Creating a Resource Group
To create a new resource group, use the az group create
command. You must specify the name of the resource group and its location.
az group create --name MyResourceGroup --location eastus
Listing Resource Groups
To see all the resource groups in your subscription, use the az group list
command.
az group list --output table
The --output table
option provides a nicely formatted tabular output.
Showing Resource Group Details
To get detailed information about a specific resource group, use az group show
.
az group show --name MyResourceGroup
Deleting a Resource Group
To delete a resource group and all the resources within it, use the az group delete
command. This action is irreversible.
az group delete --name MyResourceGroup --yes --no-wait
Tip: Use the --yes
parameter to automatically confirm the deletion without prompting. The --no-wait
parameter allows the command to return immediately while the delete operation runs in the background.
Listing Resources in a Resource Group
To see all the resources contained within a specific resource group, use az resource list
.
az resource list --resource-group MyResourceGroup
Deploying Resources to a Resource Group
You can deploy resources using ARM templates or Bicep files. For example, to deploy an ARM template:
az deployment group create --resource-group MyResourceGroup --template-file mainTemplate.json --parameters @parameters.json
Best Practices
- Group resources that share a common lifecycle. For example, all resources for a web application can be in one group.
- Place resources in the same region as the resource group for easier management, although this is not strictly required.
- Use descriptive names for your resource groups.
- Leverage RBAC roles at the resource group level for efficient access management.
Important: Deleting a resource group is a destructive operation. Ensure you understand which resources will be deleted before proceeding.