2.2.3 Create an Azure VM

Creation of Azure VMs.

  1. From Cloud Shell, run az vm create to create a Linux VM:

az vm create \
--resource-group "GROUP_NAME" \
--public-ip-sku Standard \
--image Ubuntu2204 \
--admin-username azureuser \
--generate-ssh-keys

The \ extends the command to new lines.

  1. Run az vm extension set to configure Nginx:

az vm extension set \
--resource-group "GROUP-NAME" \
--vm-name my-vm \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--version 2.1 \
--settings '{"fileUris":["https://raw.githubusercontent.com/MicrosoftDocs/mslearn-welcome-to-azure/master/configure-nginx.sh"]}' \
--protected-settings '{"commandToExecute": "./configure-nginx.sh}'

This uses the custom script extension to run a BASH script on the VM. When this runs:

  1. Runs apt-get update to get latest package information.

  2. Install Nginx.

  3. Sets the home page to print a welcome message.