Hantera Azure-resurser med hjälp av Azure CLI

Lär dig hur du använder Azure CLI med Azure Resource Manager för att hantera dina Azure-resurser. Information om hur du hanterar resursgrupper finns i Hantera Azure-resursgrupper med hjälp av Azure CLI.

Distribuera resurser till en befintlig resursgrupp

Du kan distribuera Azure-resurser direkt med hjälp av Azure CLI eller distribuera en Resource Manager mall för att skapa Azure-resurser.

Distribuera en resurs

Följande skript skapar ett lagringskonto.

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
echo "Enter the location (i.e. centralus):" &&
read location &&
echo "Enter the storage account name:" &&
read storageAccountName &&
az storage account create --resource-group $resourceGroupName --name $storageAccountName --location $location --sku Standard_LRS --kind StorageV2 &&
az storage account show --resource-group $resourceGroupName --name $storageAccountName 

Distribuera en mall

Följande skript skapar distribuera en snabbstartsmall för att skapa ett lagringskonto. Mer information finns i Snabbstart: Skapa ARM-mallar med Visual Studio Code.

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
echo "Enter the location (i.e. centralus):" &&
read location &&
az deployment group create --resource-group $resourceGroupName --template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.storage/storage-account-create/azuredeploy.json"

Mer information finns i Distribuera resurser med Resource Manager mallar och Azure CLI.

Distribuera en resursgrupp och resurser

Du kan skapa en resursgrupp och distribuera resurser till gruppen. Mer information finns i Skapa resursgrupp och distribuera resurser.

Distribuera resurser till flera prenumerationer eller resursgrupper

Vanligtvis distribuerar du alla resurser i mallen till en enskild resursgrupp. Det finns dock scenarier där du vill distribuera en uppsättning resurser tillsammans men placera dem i olika resursgrupper eller prenumerationer. Mer information finns i Distribuera Azure-resurser till flera prenumerationer eller resursgrupper.

Ta bort resurser

Följande skript visar hur du tar bort ett lagringskonto.

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
echo "Enter the storage account name:" &&
read storageAccountName &&
az storage account delete --resource-group $resourceGroupName --name $storageAccountName 

Mer information om hur Azure Resource Manager beställer borttagning av resurser finns i borttagning av Azure Resource Manager resursgrupp.

Flytta resurser

Följande skript visar hur du tar bort ett lagringskonto från en resursgrupp till en annan resursgrupp.

echo "Enter the source Resource Group name:" &&
read srcResourceGroupName &&
echo "Enter the destination Resource Group name:" &&
read destResourceGroupName &&
echo "Enter the storage account name:" &&
read storageAccountName &&
storageAccount=$(az resource show --resource-group $srcResourceGroupName --name $storageAccountName --resource-type Microsoft.Storage/storageAccounts --query id --output tsv) &&
az resource move --destination-group $destResourceGroupName --ids $storageAccount

Mer information finns i Flytta resurser till en ny resursgrupp eller prenumeration.

Lås resurser

Låsning hindrar andra användare i din organisation från att oavsiktligt ta bort eller ändra kritiska resurser, till exempel Azure-prenumeration, resursgrupp eller resurs.

Följande skript låser ett lagringskonto så att kontot inte kan tas bort.

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
echo "Enter the storage account name:" &&
read storageAccountName &&
az lock create --name LockSite --lock-type CanNotDelete --resource-group $resourceGroupName --resource-name $storageAccountName --resource-type Microsoft.Storage/storageAccounts 

Följande skript hämtar alla lås för ett lagringskonto:

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
echo "Enter the storage account name:" &&
read storageAccountName &&
az lock list --resource-group $resourceGroupName --resource-name $storageAccountName --resource-type Microsoft.Storage/storageAccounts --parent ""

Följande skript tar bort ett lås för ett lagringskonto:

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
echo "Enter the storage account name:" &&
read storageAccountName &&
lockId=$(az lock show --name LockSite --resource-group $resourceGroupName --resource-type Microsoft.Storage/storageAccounts --resource-name $storageAccountName --output tsv --query id)&&
az lock delete --ids $lockId

Mer information finns i Låsa resurser med Azure Resource Manager.

Tagga resurser

Taggning hjälper till att organisera din resursgrupp och dina resurser logiskt. Mer information finns i Använda taggar för att organisera dina Azure-resurser.

Hantera åtkomst till resurser

Rollbaserad åtkomstkontroll i Azure (Azure RBAC) är det sätt som du hanterar åtkomst till resurser i Azure. Mer information finns i Lägga till eller ta bort Azure-rolltilldelningar med Azure CLI.

Nästa steg