title | description | author | ms.topic | ms.date | ms.custom |
---|---|---|---|---|---|
Manage resource groups - Azure CLI |
Use Azure CLI to manage your resource groups through Azure Resource Manager. Shows how to create, list, and delete resource groups. |
mumian |
conceptual |
09/26/2024 |
devx-track-azurecli, devx-track-arm-template |
Learn how to use Azure CLI with Azure Resource Manager to manage your Azure resource groups. For managing Azure resources, see Manage Azure resources by using Azure CLI.
-
Azure CLI. For more information, see How to install the Azure CLI.
-
After installing, sign in for the first time. For more information, see How to sign in to the Azure CLI.
A resource group is a container that holds related resources for an Azure solution. The resource group can include all the resources for the solution, or only those resources that you want to manage as a group. You decide how you want to add resources to resource groups based on what makes the most sense for your organization. Generally, add resources that share the same lifecycle to the same resource group so you can easily deploy, update, and delete them as a group.
The resource group stores metadata about the resources. When you specify a location for the resource group, you're specifying where that metadata is stored. For compliance reasons, you may need to ensure that your data is stored in a particular region.
To create a resource group, use az group create.
az group create --name demoResourceGroup --location westus
To list the resource groups in your subscription, use az group list.
az group list
To get one resource group, use az group show.
az group show --name exampleGroup
To delete a resource group, use az group delete.
az group delete --name exampleGroup
For more information about how Azure Resource Manager orders the deletion of resources, see Azure Resource Manager resource group deletion.
You can deploy Azure resources by using Azure CLI, or by deploying an Azure Resource Manager (ARM) template or Bicep file.
The following example creates a storage account. The name you provide for the storage account must be unique across Azure.
az storage account create --resource-group exampleGroup --name examplestore --location westus --sku Standard_LRS --kind StorageV2
To deploy an ARM template or Bicep file, use az deployment group create.
az deployment group create --resource-group exampleGroup --template-file storage.bicep
The following example shows the Bicep file named storage.bicep
that you're deploying:
@minLength(3)
@maxLength(11)
param storagePrefix string
var uniqueStorageName = concat(storagePrefix, uniqueString(resourceGroup().id))
resource uniqueStorage 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: uniqueStorageName
location: 'eastus'
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
supportsHttpsTrafficOnly: true
}
}
For more information about deploying an ARM template, see Deploy resources with Resource Manager templates and Azure CLI.
For more information about deploying a Bicep file, see Deploy resources with Bicep and Azure CLI.
Locking prevents other users in your organization from accidentally deleting or modifying critical resources.
To prevent a resource group and its resources from being deleted, use az lock create.
az lock create --name LockGroup --lock-type CanNotDelete --resource-group exampleGroup
To get the locks for a resource group, use az lock list.
az lock list --resource-group exampleGroup
To delete a lock, use az lock delete.
az lock delete --name exampleLock --resource-group exampleGroup
For more information, see Lock resources with Azure Resource Manager.
You can apply tags to resource groups and resources to logically organize your assets. For information, see Using tags to organize your Azure resources.
To assist with creating ARM templates, you can export a template from existing resources. For more information, see Use Azure CLI to export a template.
To manage access to a resource group, use Azure role-based access control (Azure RBAC). For more information, see Add or remove Azure role assignments using Azure CLI.
- To learn Azure Resource Manager, see Azure Resource Manager overview.
- To learn the Resource Manager template syntax, see Understand the structure and syntax of Azure Resource Manager templates.