Azure CLI
The Azure CLI is a command-line program to connect to Azure and execute administrative commands on Azure resources. It runs on Linux, macOS, and Windows and allows administrators and developers to execute their commands through a terminal or command-line prompt
Example command that restarts a virtual machine:
az vm restart -g MyResourceGroup -n MyVm
Can be used in two different ways:
- installed locally
- used from a browser through the Azure Cloud Shell
Example of installing it for Mac:
brew update && brew install azure-cli
To sign in we type:
az login
typing the above will take you to a browser where you are asked to login. Once that is done you are good to go.
Commands
Commands in the CLI are organized as commands _of _groups
Next up let's see what commands we have at our disposal:
az group
, for resource groupsaz vm
, for virtual machinesaz storage account
, for storage accountsaz keyvault
, for managing keyvaultaz webapp
, for managing webappsaz sql server
, for managing sql server databasesaz cosmosdb
, for managing cosmosdb
Searching for commands names containing the word secret
, type the following:
az find -q secret
Interactive mode
The CLI offers an interactive mode that automatically displays help information and makes it easier to select subcommands.
To use type:
az interactive
Creating a storage account
Every storage account must belong to an Azure resource group
. A resource group
is a logical container for grouping your Azure services. When you create a storage account, you have the option to either create a new resource group
, or use an existing resource group
.
Let's first look at how to create a resource group:
az group create \
--name resourceForStorageAccount \
--location westeurope
The results of running it should look something like this:
provisioningState
should say Succeeded
Next up let's create the actual storage account:
az storage account create \
--name storageaccount666 \
--resource-group resourceForStorageAccount \
--location westeurope \
--sku Standard_LRS \
--kind StorageV2
Storage account names needs to be lowercase
Also this one will answer with a long JSON response. Ensure the provisioningState
says Succeeded
Let's have a look at our resource group in our Azure portal
We can click
Resource groups
in the menu to the left and on the top middle we can search for our resource group resourceForStorageAccount
. Doing so leads to a search list and as you can see from the image above we are looking at the detail page for the resource group. One thing that is listed is all the things associated with it. For now that's only our storage account storageaccount666
. So now we clearly see the azure cli
is working well.
Now that we are done we can either choose to let everything remain as it is or we can clean up our used resource. If we opt for the latter we should type the following:
az group delete --name resourceForStorageAccount