Microsoft Docs

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

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

Important: Deleting a resource group is a destructive operation. Ensure you understand which resources will be deleted before proceeding.