Anyone who wants to independently create or manage resources in their Azure account must know how to use the Azure Resource Manager. Apart from the Graphical User Interface (GUI, the Azure Portal), Infrastructure-as-Code templates (IaC) and PowerShell, there is another approach: the Azure Command-Line Interface (CLI).
In contrast to the approach with e.g. the cloud shell, which often entails a lot of copying and pasting, the work with Azure CLI is easier. It allows direct execution from the file as well as syntax highlighting and auto-completion. Furthermore, a series of commands can be executed together, as with a PowerShell script.
To do this, however, one must know how to properly save, execute and repeat scripts that have been created. I show this in the following two hacks.
The following tools are required to use Azure CLI:
• Visual Studio Code
• Azure CLI
• CLI extension
– to save as a scrapbook file (.azcli)
Only through these tools and the subsequent saving as a scrapbook file (.azcli) can one work with autocompletion in addition to syntax highlighting. So when you enter your cli command, keywords are completed and, provided you are logged into your Azure account, additional names, e.g. for resource groups, are suggested and checked.
Now let's take a closer look at the execution. With Visual Studio Code, there are two options: Execute the jobs per line or execute them all together.
Create a resource group
Create a storage account
List the storage keys
Print the connection string
az group create --location northeurope --name az204blobdemo az storage account create --name stodemo08154711 --location northeurope --resource-group az204blobdemo --sku Standard_LRS az storage account keys list -g az204blobdemo -n stodemo08154711 az storage account show-connection-string -g az204blobdemo -n stodemo08154711
Now change to the path of the file in the terminal and simply enter the following: ./filename.azcli – the commands are then executed in the corresponding order:
Have fun coding with Azure CLI!
You can find more articles by Thomas Hafermalz and on the topic of the cloud here:
Monitoring in the Azure Cloud