Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
An Azure resource group is a container that holds related resources for an Azure solution. A resource group might contain storage, virtual machines, apps, dashboards, services, or anything you deal with in Azure.
The Azure Command-Line Interface (CLI) allows you to create, persist, and set default Azure resource groups. The Azure CLI also enables you to clean up resources after they're created.
Azure Region Identification
Azure customers can choose to deploy resources in several different regions. Sometimes, customers can reduce costs by selecting nearby regions that offer the same services. If a nearby region is identified, a message displays the region for selection in future deployments.
In the following example, the az config
command is used to turn off the region recommendation
message:
az config set core.display_region_identified=no
For more information about Azure regions, see Choose the right Azure region for you.
Create a resource group
To create a resource group, use the az group create command:
az group create --name MyResourceGroup --___location eastus
A resource group is associated with a single ___location. To see all the locations supported in your current subscription, run the az account list-locations command:
az account list-locations
To see all the resource groups for your current subscription, use the az group list command:
az group list --output table
Tip
The --output
parameter is a global parameter, available for all commands. The table
value
presents output in a friendly format. For more information, see
Output formats for Azure CLI commands.
When you create a resource, it resides within a resource group. The following example shows a storage account created using the az storage account create command:
az storage account create --resource-group MyResourceGroup --name storage134 --___location eastus --sku Standard_LRS
To remove a resource group, run the az group delete command:
az group delete --name MyResourceGroup
When you remove a resource group, you delete all the resources that are contained within it. You can't undo this action. If you try any of the commands in this article, deleting the resource groups you create cleans up your account.
Set a default resource group
You can set a default resource group for all the commands that you run from your local Azure CLI or Azure Cloud Shell. Azure CLI stores this configuration locally in a config file. To see your current configuration, run the az config get command:
az config get
The result shows default resource groups and other default values. If you're using Azure CLI for the first time, the results might be empty.
To set a default resource group for your Azure CLI installation, run the az config set command:
az config set defaults.group=MyResourceGroup
The command sets a value for a specified key, in this case, defaults.group
. For available
configuration options, see Azure CLI configuration.
Note
The az config set command doesn't verify the existence of the resource group you enter. The command simply stores the key-value pair.
After you run the command, the following two commands give you the same result:
az storage account create --resource-group MyResourceGroup --name storage01 --___location eastus --sku Standard_LRS
az storage account create --name storage01 --___location eastus --sku Standard_LRS
A resource group is associated with a subscription. If your organization has more than one subscription, you must change to the desired subscription before working with a resource group in that subscription. If the default value of a resource group doesn't belong to your current subscription, an error results. For more information about multiple subscriptions, see Use multiple Azure subscriptions.
You don't have to reset the default to use other resource groups. Instead, specify the resource group:
az group create --name OtherResourceGroup --___location eastus
az storage account create --resource-group StorageGroups --name storage03 --___location westus --sku Standard_LRS
The default value is for you only. It doesn't affect other users or changes you make through the Azure portal.
If you're using persisted parameter values, as described in this article, those values take precedence over defaults set in the config file.
Set a resource group lock
As an administrator, you might need to lock a resource group to prevent users from deleting or modifying it. For more information, see Lock resources to prevent unexpected changes.
In Azure CLI, use the az group lock commands. For instance, the az account lock create command can prevent users from deleting a resource group:
az group lock create --name "Cannot delete resource group" --lock-type CanNotDelete
Note
You need to have contributor
permissions on a resource group to create or change locks.
To see the current locks on your resource group, use the az group lock list command:
az group lock list --output table
Clean up resources
If you tried any of the commands in this article, you can remove the resources you created using the az group delete command:
az group delete --name MyResourceGroup
az group delete --name OtherResourceGroup
az group delete --name StorageGroups
This command removes the group and all its associated resources.