Skip to main content

The goodness of Azure CLI Interactive shell

Background

Off late I have been working a lot with terminal and command line interface (CLI) for things like Docker, Azure, Kubernetes etc. While working with these wonderful technologies they provide an easy way to auto-complete different commands. Without auto-completion its a nightmare to remember the syntax for each & every command. Even with auto-completion enabled sometimes it is really a pain to remember different parameters a command can take. Sometimes you have multiple options which can be assigned as a parameter value. Most of the times I find using the help feature with –h or –help option to know all these details about the command, its parameters and available options.

If you are starting new with some technology like Kubernetes or with cloud provider like Azure which has various services which can be managed using CLI it can be really difficult to get started. When it comes to Azure CLI there is an easy option called Interactive which simplifies things to a great extent. This short post is about my experience of using the Azure CLI interactive mode which I happened to discover by accident.

Azure CLI Interactive mode

First of all you need to install the latest version of Azure CLI 2.0. We need to execute the following command in our favorite terminal. I use zsh as my default terminal along with the oh-my-zsh plugin.

az interactive 

Once we enter the interactive mode, the terminal changes look & feel. Lets use some of the commands from our previous post on provision Kubernetes cluster in AKS.

Auto suggestion resource names

The moment I start typing, I can see auto suggestion for different resources that can be managed using Azure CLI. AZ autocomplete resource name

Lets choose aks as the resource we want to interact with using the command line. We will use the create command.

Command details

AZ command details

Once we have chosen the command, the bottom part of the screen is refreshed automatically or I should say magically to display relevant details of the command. We can find command description in the first pane. The next pane shows some examples how the command can be executed. In the above screenshot we can see 3 examples how the create command can be invoked with different parameters. At the bottom pane we can see the keyboard shortcut keys for layout(F1), default values (F2) etc. On the rightmost corner we can also see the current active subscription.

Parameter details with description

As soon as we finish writing create, we can see the auto suggestion popping up for the parameters along with the description of the parameter.

AZ parameters list with explanation

This is simply amazing. I get to know which are the required parameters and which are the optional parameters at one glance. I also get helpful description for each parameter with hints like in case of kubrnetes-version. Here is a quick example of the hint

AZ parameter suggestions with default help

I did not know that the default group can be configured using the command az configure –default group=<name>. I find it quite useful that such hints can help to learn the different commands quite fast.

Filter & Auto suggest existing resources

Another interesting feature I found out about the interactive shell was its capability to filter existing resources. Let me take an example once again. I have some resource groups already created. When I try to add the –resource-group parameter, I get an auto suggestion for all the available groups as shown below

AZ autocomplete existing resources

I no longer need to remember the lengthy names of different resources.

Conclusion

I touched just the tip of the iceberg during this post. I found it very useful and a huge productivity gain when I started using the interactive shell. I hope you can make good use of this when you are trying to familiarize yourself with different options related to managing numerous resources using Azure CLI. Playing around with Azure command line has never been so much fun before. Interactive command line makes the whole learning experience much more exciting. I am pretty sure that once you get used to the amazing az cli you would never want to go back to the –h –help option ever again. I wish other tools will also implement such features.

Until next time code with passion and strive for excellence.

Comments

Popular Posts

Unit Test Application Configuration Settings

BackgroundAll the post I had written this month so far were related to the Entity Framework learning series. This time I thought of taking a diversion and share a quick method of unit testing setting which might be stored in the Application Configuration file (App.config) of a DotNet application. Unit Test Application Configuration SettingsLets fire up Visual Studio and create a simple console application. You can name it whatever you want. I have named the project as AppConfigTest. Once the project is created right click on Add and select Add New Item option in the solution explorer window. Select Application Configuration File option and click Add. This will automatically name the new file as App.config.Since this file used to configure settings at application level there is a possibility of someone changing these setting unknowingly. It can lead to severe problems later. It might also happen that the settings are different in different environments like development machines, test s…

Integrate SQL Server 2017 Linux with ASP.NET Core using Docker

In the previous post, we saw how to initialize a SQL Server 2017 on Linux database running inside Docker container. This post is continuation of my exploration about Docker containers for stateful applications. In this post we will explore how to integrate the SQ Server 2017 on Linux container with ASP.Net Core Web API also running inside a Docker container. We will perform following activitiesUpdate Docker compose file to build the SQL server imageUpdate Web API project to use SQL Server Database instead of In memory databaseBuild and run the application containers using Docker compose commandsQuery Data from SQL container using the MVC web front endUpdate Docker compose file to build the SQL server imageDocker provides Docker Compose as a tool for defining and running multi-container Docker applications. I already have an existing docker compose file which I have been using for my series of post on implementing continuous deployment of multi container apps. In a compose file we defi…

Setup MacBook almost at the speed of light

BackgroundI bought a new MacBook recently. It is always fascinating to setup your new machine. But it is also a pain to look for all the tools that you have on your old machine and port it to the new machine. Sometime back I started learning abount Ansible which helps to automate routine tasks. I came across a blog by Jeff Geerling who is the author of book Ansible for DevOps. Jeff and many others had used Ansible to setup their machines. I took inspiration from these guys blogs to automate the process of setting up a new MacBook Pro. Here is my experience.Why Ansible?Ansible is very easy to understand. It uses human readbale YAML syntax to describe the different actions which needs to be performed. Group of Ansible actions which are executed as part of a playbook are idempotent. It does not have a side effect on the setup. The same playbook can be run multiple times. Only the changes will be applied incrementally.
How did I use Ansible?I started off by cloning the Git repository of Ge…