Exercise 4 – creating resources using the Azure CLI from Cloud Shell
In this exercise, you’ll learn how to interact with Azure environments using the Azure CLI as the CLI tool and Cloud Shell as the shell environment for running commands.
The following subsections will show you how to create all the necessary resources for this exercise. These have been segregated into tasks for ease of understanding:
Task – accessing the Azure portal
- Log in to the Azure portal by going to https://portal.azure.com. Alternatively, you can use the Azure desktop app: https://portal.azure.com/App/Download.
Task – setting up Cloud Shell (skip this task if you’ve already completed it)
2. Click on the Cloud Shell code icon on the top toolbar of the portal. If this is the first time you have used Cloud Shell and no storage has been mounted to persist files, you will be prompted to create a storage account. Select your subscription and then click on Create storage:
Figure 6.31 – Cloud Shell setup
3. Once the storage account has been created, you will be connected to a terminal running the shell environment you will use to run commands.
Task – creating a resource group
- Bash should be set as the CLI within Cloud Shell for this exercise.
- To create a resource group, enter the following command:
az group create -l uksouth -n Project1-RG
6. The output will look as follows:
Figure 6.32 – Creating a resource group
- To show the resource group that has just been created, enter az group list or az group list –out table.
- The created resource group will also appear in the portal UI.
Figure 6.33 – Showing the created resource group
Task – creating a virtual machine
9. To create a virtual machine, enter the following code:
az vm create \
–resource-group Project1-RG \
–name myVM \
–image win2019datacenter \
–admin-username azureuser
10. When prompted, enter a username and password:
Figure 6.34 – Creating a virtual machine
- You will see a Running message while the virtual machine is being created.
- Once the virtual machine has been created, the following information will be returned:
Figure 6.35 – Virtual machine created
13. To show the virtual machine that has just been created, enter the following command:
az vm list –out table
14. The created virtual machine will also appear in the portal UI.
Figure 6.36 – Showing the created virtual machine
In this exercise, we created a resource group and a virtual machine using the Azure CLI from Cloud Shell. The following exercise looks at using Azure Service Health in the Azure portal.