The Azure Command Line Interface (CLI) is a developer tool that allows users to control Azure services using command line commands. It is a cross-platform tool that can be installed in a number of ways (Windows, Mac, Linux, Docker and Azure Cloud Shell).
It also has the ability to have a number of extensions installed to add additional functionality, assisting with your development and deployments to the cloud. One of these extensions is the newly released AZ Interactive extension that is now in preview.
Useful links:
What is AZ Interactive?
Using any CLI can sometimes be cumbersome, especially if you are new to the tool. AZ Interactive is a new AI-based extension for the Azure CLI and somewhat of a cheat code for developers. It allows you to interact with Azure resources in a more interactive and intuitive way than usual. It is a great tool for those who are new to the Azure CLI and want to learn how to use it, or for those who are more experienced and want to be more efficient.
It sets out to solve a few problems that developers face when using the Azure CLI:
- Discoverability of services, commands and parameters
- Reducing the time taken to learn the Azure CLI and its commands
- Speed up the process of writing commands and deploying resources
Prerequisites
To use AZ Interactive, you will need to have the Azure CLI installed. You can find instructions on how to install the Azure CLI here.
Installing AZ Interactive
To install the AZ Interactive extension, you will need to run the following command from your terminal (once you have the Azure CLI installed):
az extension add --name interactive --upgrade
This command will install the extension and any dependencies that are required. Once the installation is complete, you can run the following command to start the interactive mode:
az interactive
Those are the only commands you need to install and start using AZ Interactive. It is that simple!
Once you have it running, your terminal will look something like this:
Using AZ Interactive
Now you have this awesome tool installed, what sort of super power does it provide? Let's take a look at some of the features.
Command Suggestions
One of the great features of AZ Interactive is the command suggestions. As you type, it will suggest commands that match what you have typed. It is somewhat similar to tab completion you may find in other tools, but it is a lot more intuitive and it will match commands based on what you have typed so far and allow you to chose from a list.
Command Scenarios
Another great feature of AZ Interactive is the command scenarios. This is where AZ Interactive allows you to select a scenario and then it will guide you through the process of creating the resources required for that scenario and provide you with the commands needed to do so.
Search for commands and scenarios
You also have a search capability that allows you to search for commands, parameters and resources. This is great if you know what you are looking for and want to have the CLI generate the command(s) for you. For instance, if you search with the prompt "connect an app service to mongodb", it will generate a number of commands within a scenario that you can run.
Running commands outside of interactive mode
You may notice that you are abstracted away from your normal terminal shell at this point and tucked into an "az interactive" shell. This does not mean that you cannot run commands outside of interactive mode. You can run any command you like by prefixing it with "#". This will run the command as normal and return the output to the terminal for you. For example, if I want to know my current working directory, I would typically run the command "pwd". In interactive mode, I would run "#pwd" and it would return the output to the terminal in the same manner.
JMESPath query support
This is a powerful feature and probably one of my favourites. JMESPath is a query language for JSON that allows you to extract and transform elements of JSON. AZ Interactive supports JMESPath queries and allows you to run them against the output of commands. This is great if you want to filter the output of a command to only return the data you are interested in. For example, if I want to get a the name of my resource group from the JSON object returned in a previous command I can do just that by using ??name
as seen in the example below.
This is not all either. You can also use this to inject jmespath query into future commands allowing you to use this data throughout your session. For example, if I want to get the name of my resource group and use it in a command to delete the resource group, I can do that by using ??name
in the command as seen below.
Status codes
When running terminal commands you may be used to seeing a status code returned. This is a number that indicates whether the command was successful or not. This is also supported within this extension and you can find the previous status code of each command by simply using the $
symbol. This will return the status code of the previous command.
I previously ran a command to delete a resource group and it returned a status code of 0, indicating that the command was successful.
Setting Scope
When you are working within a certain command group you can set the scope of the commands. This means that you can run commands without having to specify the command group every time. For example, if I want to run a number of commands to work within resource groups, I can set the scope to be groups using the command %% group
. From there, I can run any command within that group without having to specify the prefix every time. This saves time and acts as a shorthand for you.
Fun colour themes
This is a fun way to spice up your terminal. You have the ability to change the colours you want to use with a number of different styles. This changes the text colour, drop down lists and more!
By default, all of the AI capabilities are turned on but if you are not a fan of having all the noise in your terminal and you want to get back to the basics, you can turn it off by running the command az config set interactive.enable_recommender=False
.
Overall this is a great tool to use and I would highly recommend it to anyone who is new to the Azure CLI or wants to speed up their development and deployment processes from within the terminal. It is a great tool to have in your arsenal and I am sure it will only get better as it is developed further.
For more examples of how to use the Azure CLI Interactive mode, you can checkout the documentation here.
Happy terminal'ing!
If you have any questions or some feedback, I'd love to hear so feel free to drop me a line 📝
Top comments (0)