In this blog, we will cover the details needed to get better understanding of Azure CLI command structure, that is required to understand and master to prepare & clear AZ-104.
Here, we will focus on understanding Azure CLI command structure that you need to be aware to create resources.
Azure CLI command structure is based on the Bash command structure and Bash commands and having a pre-defined command for the command that you need to understand to get hands-on as well to be aware of various commands that you can create.
It’s a vast set of commands that you will not be able to remember all of them.
So understanding the structure, how it would work and how it is structured would really
help you to apply the same in your work project or even for the certification.
Azure CLI has a pre-defined structure starting with the keyword AZ.
AZ stands for Azure CLI. If you have installed the CLI command tool in your laptop, you can just go and search for AZ and type in AZ and enter. If it is installed successfully, you will see the syntax error or you will say command not found.
Coming to the structure, as I said, AZ is the keyword which will indicate to the command
line that we are trying to create or manage infrastructure in Azure.
Group
Followed by the first command or first parameter is the group parameter. Now a group typically indicates the service or Azure service or resource that we are trying to create.
It could be a virtual machine, a resource group, a storage, an app service. These are the services that Azure provides and the first parameter you are going to indicate this CLI that you are trying to do some operations on this particular service.
If you say AZ space group, the command line understands you are trying to do something
with an resource group.
While if you say AZ space sub, it understands you are trying to do something on the subscriptions.
Subgroup
The subgroup indicates if the service that you are defined in a group has subcomponents.
For example, if you are trying to create a storage account and if you already have a storage account and you are trying to create a container on it or you are trying to create a table,
then you need the subgroup would indicate the service that the sub service you are trying
to create in the storage.
If you are trying to create a container, you would say AZ space storage space container.
So that the container is the subgroup name because of the service the storage provides.
Now in some cases, the subgroup may not be available in case of a resource group and
case of an app service.
Command
Followed by the specific command that you are trying to do. It could be about listing the command, listing the services, create a new service, get the details around the existing service.
So you could all the any comment that you are trying to do with the specific group and
the subgroup, you need to specify the same.
Mandatory Parameters
Next what is specified the command, you will have to specify the mandatory parameters based on the group, subgroup and the command that you have chosen.
If you are trying to pay it a VM, you may not have a subgroup but it will have you and
you are trying to create a VM command is the create and then you need to specify the
resource group as a mandatory.
You need to specify the virtual machine name as a mandatory.
So some of the depending on the command, the mandatory parameters would vary and you would be able to anytime use and understand the command by using the help statement.
But once you give the group, subgroup and the command, it follows by the mandatory parameters of that command.
Optional Parameters
Finally, you may have some optional commands. Again, depending on the command and the group and the service you are trying, the optional parameters will vary and you will have to understand those optional parameters and accordingly specify.
For example, for any, when you are creating your stories or a VM, the SKU might be, there
might be default SKU select chosen. Few of the optional parameters would be:
- SKU
- Tags
So you will have to specify the same depending on your command, both the mandatory parameters as well as the optional parameters.
Now let’s look at a couple of examples of how we can relate these groups of group command parameter and options in a real example. Let’s say you are trying to create a VM.
We are going to start with AZ to indicate that you are trying to work on Azure CLI.
VM is a keyword or a shortboard for virtual machine which Azure CLI understands that you
are trying to do some operation on a VM service.
Next you are going to specify the action.
Now in case of a VM, there is no subgroup.
So we are directly going to say give the command, which is your great command, followed by the mandatory parameters.
Right?
In this case, resource group and the name of the virtual machine is mandatory.
So you are going to specify this along with other mandatory option parameters.
By executing this command, it would create a new VM with the name VM name and my resource group inside my resource group that you have created.
And this command would not create a new resource group if it doesn’t exist, but it would go
on and create the VM inside the virtual machine.
Conclusion
Having a good understanding Azure CLI command structure really helps you to one prepare for the AZ 104 exam and clear and prepare for some of the questions you would get with respect to fill in the fill in the blanks or fill in the command gaps, you know, it could be those kind of questions.