Skip to main content

Azure CLI Essentials

Course

Intro Video

Photo of James Lee

James Lee

Training Architect

Length

04:38:00

Difficulty

Beginner

Videos

19

Hands-on Labs

2

Course Details

This beginner-level course teaches the essentials of using the Azure CLI to manage your Azure environment using the command line.

You will learn important concepts of the Azure CLI to create and manage resources in Azure, and also gain a basic understanding of how to build your own scripts.

These essential skills will help you use Azure CLI to simplify and automate your administrative and development tasks.

Interactive Diagram: https://interactive.linuxacademy.com/diagrams/IntrotoAzureManagement.html

Syllabus

Course Introduction

Welcome to the Course

Course Introduction

00:03:33

Lesson Description:

Welcome to this course on the Azure Command line Interface (CLI) where we will become confident and competent with the following:The syntax, structure, and usage of Azure CLI.Managing Azure through Azure CLI.Building scripts in the Bash shell that use Azure CLI. This lesson provides a walkthrough of the objectives of the course, the benefits of using Azure CLI, and the types of topics we will discuss. Following along with this course: To follow along with this course, you can either use your own installation of Azure CLI, or you can use the Azure CLI built into the Cloud Shell within the Azure Portal. If you would like to perform the creation and management tasks covered in this course, you can either use your own Azure subscription or utilize the hands-on labs.

Course Support and Feedback

00:02:24

Lesson Description:

At Linux Academy, helping our students learn is something we all are very passionate about. To help you and ensure our courses meet your expectations, we provide a number of ways to communicate and connect more directly. This lesson covers how to leave feedback, ask questions, or just reach out and chat with course authors and other students. Helpful linksLinux Academy Community SlackLinux Academy CommunityReach out to me directly: james.lee@linuxacademy.com

About the Training Architect

00:01:03

Lesson Description:

G'day everyone (as we say in Australia)! It's great to be working with you. My name is James Lee, and I'm the author of this course. I'm really excited to be taking this journey on learning Azure CLI Essentials with you. I genuinely enjoy chatting with you all, so please do feel free to reach out to me directly via Slack or in the community.Twitter: @jamesdpleeLinkedIn: James LeeEmail: james.lee@linuxacademy.com

Using the Azure CLI Essentials Guide

00:02:07

Lesson Description:

In this brief lesson we take a look at the purpose of the Azure CLI Essentials Guide as well as how to navigate it. The Azure CLI Essentials Guide can be found here: https://www.lucidchart.com/documents/view/93d52a7f-335b-489e-a663-dd7fefe13f11/1

Introduction to Azure CLI

Azure Management

Overview of Azure Management

00:08:41

Lesson Description:

Throughout this video we will look at a high-level overview of the Azure management framework. This includes:Azure Management ToolsAzure Resource Manager (ARM) Application Programming Ingerface (API)Azure Resources This overview provides some context about where the Azure CLI toolset fits within the Azure management framework. We also discuss some key differences between Azure CLI and PowerShell.

Azure Essentials

00:08:43

Lesson Description:

This lesson provides a high-level overview of Azure essentials. We take a look at key elements of Azure such as:Resource hierarchyAccess management Identity These foundational concepts are important as we learn more about Azure CLI and interact with Azure in various ways. Note: If you are new to Azure and find these concepts difficult to understand, you may be interested in taking our Azure Fundamentals course.

Command Line Shells

00:06:17

Lesson Description:

Throughout this lesson we discuss command line shells to better understand how they can influence the way we work with the Azure CLI. While the Azure CLI is fully self-contained, the way we interact with the file system, scripts, and data can all change depending on the command line shell we use. Throughout this course we use the Bash command line shell, so it also helps to discuss some key differences from Microsoft PowerShell. New and helpful commands:Listing all resource groups: az group list All commands used if you wish to follow along:Bash:

ls
pwd

az group list
PowerShell:
az group list

Azure CLI

Getting Started with Azure CLI

Getting Started with Azure CLI

00:14:44

Lesson Description:

Before we work with the Azure CLI, we first need to install it, connect it, and configure it. In this lesson we perform an installation of Azure CLI on an Ubuntu Linux server. This process is quite similar for other versions of Linux and macOS. Once the installation is complete, we connect to an Azure subscription and walk through the configuration of default settings for our user profile. Commands and Links Used In This LessonAzure CLI installation documentationChecking the Azure CLI version: az --versionInteractively logging in to Azure: az loginListing the available subscriptions in a table: az account list -o tableSetting a subscription to be active: az account set -s "subscription"Changing configuration options: az configure All commands used if you wish to follow along:

sudo apt-get update
sudo apt-get install curl apt-transport-https lsb-release gnupg

curl -sL https://packages.microsoft.com/keys/microsoft.asc | 
    gpg --dearmor | 
    sudo tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null

AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | 
    sudo tee /etc/apt/sources.list.d/azure-cli.list

sudo apt-get update
sudo apt-get install azure-cli

az --version

az login

az account list -o table

az account set -s "LA Lab Subscription"

az configure

cd ~
ls -la
cd .azure
vi config

Using Azure CLI through the Cloud Shell

00:05:18

Lesson Description:

Cloud Shell is a helpful feature of the Azure Portal. It provides us with easy access to the Azure CLI without the need to install it on our computer. In this lesson we'll take a look at how to setup Cloud Shell for the first time so we can access Azure CLI from our browser. Note: Sometimes the Cloud Shell freezes and input no longer works. You can restart the Cloud Shell if this happens. Commands Used In This LessonChanging the Azure CLI configuration: az configureLogging in to Azure (not needed in the Cloud Shell): az login All commands used in this lesson if you wish to follow along:

az login
az configure

Azure CLI Command Structure and Help

00:09:15

Lesson Description:

In this lesson we look at the structure (also known as the syntax) of the az command. Understanding the sytax helps ensure we enter commands correctly and aids in the ease-of-use. We also take a look at accessing help so we can easily view documentation and examples for commands we wish to use. Tip: You can press the TAB key while typing an Azure CLI command and the system provides possible options as well as auto-completing the command. Commands Used In This LessonThe partial command for web apps: az webappThe partial command for subnets: az network vnet subnetOutputting a list of resource groups: az group listThe partial command for creating resource groups: as group createGetting help about creating a resource group: az group create -hGetting help about the resource group commands: az group -h All commands used if you wish to follow along:

az webapp
az network vnet subnet
az group list
az group create
az group create -h
az group -h
az group create -h

Creating Resources with Azure CLI

00:13:13

Lesson Description:

Let the rubber hit the road; it's time to get building. In this lesson we're going to put in practice all of the concepts we've learned so far. We have a fictitious scenario and must create some infrastructure according to a basic design. This video shows how we can use our knowledge to create real resources within Azure. Commands Used In This LessonCreating a resource group: az group create --name firstempire-rg --location australiasoutheastCreating another resource group: az group create -n hammeroftruth-rg -l "Australia Southeast"Creating a storage account: az storage account create -n firstempirestore1 -g firstempire-rgCreating a vnet with a multi-line command: az network vnet create --name firstempire-vnet1 --resource-group firstempire-rg --address-prefixes 10.1.0.0/16Listing all vnets: az network vnet listShowing a specific vnet: az network vnet show --ids <RESOURCEID> All commands used in this lesson if you wish to follow along:

az group create -h
az group create --name firstempire-rg --location australiasoutheast
az group create -n hammeroftruth-rg -l Australia Southeast
az group create -n hammeroftruth-rg -l "Australia Southeast"

az storage
az storage -h
az storage account
az storage account create
az storage account create -h 
az storage account create -n firstempirestore1 -g firstempire-rg

az network vnet create -h
az network vnet create 
--name firstempire-vnet1 
--resource-group firstempire-rg 
--address-prefixes 10.1.0.0/16

az network vnet list
az network vnet show
az network vnet show --ids RESOURCEID

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

02:00:00

Azure CLI Essentials

Azure CLI with Bash Variables - Part 1

00:14:07

Lesson Description:

Bash variables are a valuable tool when working with Azure CLI. With variables we can easily store and retrieve information to help simplify our commands. In part one of this two-part series, we discuss how to create, assign, and safely access information in variables. Note: This lesson is intended as an introduction to Bash variables only. If you are excited to learn more, see our other Bash scripting courses for more in-depth discussions. Important tasks used in this lesson:Creating a variable: name=jamesEchoing the variable on screen: echo $nameCreating a literal variable: name='$superman'Creating a variable based on the output of a command: name=$(echo helloworld)Accessing a variable that may contain whitespace: echo "$name"Specifically accessing a variable: echo ${name} All commands used in this lesson if you wish to follow along:

name=james
echo $name
echo james
name="james lee"
echo $name
name=james lee

name='$superman'
echo $name
name=$superman
echo $name

name=$(echo helloworld)
echo $name

date=$(date)
echo $date
date

echo $name
name="james lee"
az group create -n $name -l "Australia Southeast"

echo ${name}
echo ${name}hello

Azure CLI with Bash Variables - Part 2

00:13:49

Lesson Description:

Continuing from part 1, we expand our knowledge of variables by considering array variables. Array variables allow us to contain multiple pieces of related information within a single multi-dimensional variable. This lesson goes on to make use of the concepts we've learned, by creating resources using both Azure CLI and array variables. Important commands used in this lesson:Creating an indexed array: indexedA=("value one" value2 "some words")Creating an associative array: declare -A associativeArrayAssigning a value to our associative array: associativeArray[value1]="value one"Echoing the first value in the indexed array: echo ${indexedA[0]}Echoing the value from an array with the index value1: ${associativeArray[value1]} Use the following commands to create resources:declare -A book1 book1[name]="hammeroftruth" book1[rgname]="hammeroftruth-rg" book1[saname]="hammeroftruthstore" book1[vnetname]="hammeroftruth-vnet" book1[location]="australiasoutheast" az group create -n ${book1[rgname]} -l ${book1[location]} az network vnet create -g ${book1[rgname]} -n ${book1[vnetname]} --address-prefix 10.2.0.0/16 az storage account create -g ${book1[rgname]} -n ${book1[saname]} All commands used in this lesson if you wish to follow along:

indexedA=("value one" value2 "some words")

declare -A associativeArray
associativeArray[value1]="value one"

echo ${indexedA[0]}
echo ${indexedA[1]}
echo ${indexedA[2]}
echo $indexedA[2]

echo ${associativeArray[value1]}

declare -A book1
book1[name]="hammeroftruth"
book1[rgname]="hammeroftruth-rg"
book1[saname]="hammeroftruthstore"
book1[vnetname]="hammeroftruth-vnet"
book1[location]="australiasoutheast"

echo ${book1[saname]}

az group create -n ${book1[rgname]} -l ${book1[location]}
az network vnet create -g ${book1[rgname]} -n ${book1[vnetname]} --address-prefix 10.2.0.0/16  
az storage account create -g ${book1[rgname]} -n ${book1[saname]}

Azure CLI Output

00:05:50

Lesson Description:

This lesson provides a brief introduction to using Azure CLI for information output and formatting. We discuss the two main commands for outputting information (az ... list and az ... show) as well as how to format the information using the --output argument. Information output and formatting can be a really helpful feature beyond getting easy access to information. We can combine this with other features and use it for scripting or more advanced commands. This lesson provides tbe building blocks we use to expand upon in later lessons. New and important commands used in this lesson:Listing all current resource groups: az group listShowing information about a specific resource group: az group show -n rgNameListing resource groups in a different format: az group list -o OUTPUTTYPE All commands used if you wish to follow along:

declare -A book1
book1[name]="hammeroftruth"
book1[rgname]="hammeroftruth-rg"
book1[saname]="hammeroftruthstore"
book1[vnetname]="hammeroftruth-vnet"
book1[location]="australiasoutheast"

az group list
az group show -n ${book1[rgname]}
az group list -o table
az network vnet show -g ${book1[rgname]} -n ${book1[vnetname]} --output tsv
az group list -o yaml

Azure CLI Queries and Bash Pipe

00:13:26

Lesson Description:

In this lesson we look at ways to retrieve, filter, and transform the output of Azure CLI. We do this using the Bash pipeline and Azure CLI queries. Both of these tools provide an invaluable method for interacting with our resources through Azure CLI. For example, if we need to know the current date or look up resources, we can easily do so. New and important commands used this lesson: Piping list output for easier access: az group list | lessSearching the list output for text: az group list | grep "text"Cutting the first field of output from a searched list: az group list -o tsv | grep "text" | cut -f1JMESPath - querying the ID field: az group show -n name --query idJMESPath - filtering based on a field: az group list --query "[?fieldToSearch=='valueToFind']"JMESPath - filtering, selecting, and displaying specific fields: az group list --query "[?fieldToSearch=='valueToFind'].{displayName:fieldName,displayName2:fieldName2}" -o table All commands used if you wish to follow along:

# Note you can use / key to search
az group list -o json | less
az group list -o tsv
az group list -o tsv | grep "hammeroftruth"
az group list -o tsv | grep "hammeroftruth" | cut -f1
az group show -n hammeroftruth-rg --query id
az group show -n hammeroftruth-rg --query properties.provisioningState
az group list --query "[?location=='australiasoutheast']"
az group list --query "[?location=='australiasoutheast'].{RGName:name,ID:id}" -o table

Managing Resources with Azure CLI

00:11:53

Lesson Description:

In this lesson we look at three examples of managing Azure resources which have already been created. Through these examples we see there are two main types of management tasks we might perform: configuration changes and administrative operations. We perform these tasks by harnessing knowledge we've gained so far throughout the course. All commands used if you wish to follow along:

declare -A book1
book1[name]="hammeroftruth"
book1[rgname]="hammeroftruth-rg"
book1[saname]="hammeroftruthstore"
book1[vnetname]="hammeroftruth-vnet"
book1[location]="australiasoutheast"
book1[vnetID]="id"

'hammeroftruth-vnet'].id" -o tsv
book1[vnetID]=$(az network vnet list --query "[?name=='hammeroftruth-vnet'].id" -o tsv)
echo ${book1[vnetID]}

az network vnet update -h
az network vnet update --ids ${book1[vnetID]} --address-prefixes "10.200.0.0/16"

az network vnet update --ids ${book1[vnetID]} --set addressSpace.addressPrefixes[0]=10.200.0.0/16

az network vnet update --ids ${book1[vnetID]} --add addressSpace.addressPrefixes 10.201.0.0/16

az network vnet subnet create -h
az network vnet subnet create -n subnet1 --address-prefixes 10.200.1.0/24 -g ${book1[rgname]} --vnet-name ${book1[vnetname]}

az vm stop
az storage account keys list -n ${book1[saname]}
az storage account keys renew -n ${book1[saname]} --key primary

Azure CLI Extensions

00:05:16

Lesson Description:

In this video we look at how the functionality and commands available through Azure CLI can be extended using extensions. Extensions add commands to Azure CLI which are not normally available through the default installation. These might be custom features or experimental functionality for services Microsoft currently has in preview. We briefly discuss how to find and install extensions, as well as two common examples of extensions: az interactive and az find. New and helpful commands:Listing extensions: az extension listInstalling an extension: az extension add --name extensionUsing interactive mode: az interactiveUsing the find AI: az find All commands used if you wish to follow along:

az extension list -o table

az interactive
# to exit itneractive mode use CTRL+d

az find
az find "az group create"
# press Enter to exit az find

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

02:00:00

Scripting for Azure

Scripting with Azure CLI

Getting Started with Bash Scripts

00:09:29

Lesson Description:

In this lesson we discuss some of the basic components of a Bash script, and how we can use them with Azure CLI. This is an introductory lesson and is intended to provide a basic awareness of the benefits of scripting. It also explains how to build and execute a script. Helpful tipsIt is common to use the extension .sh for Bash scripts you are creating, but it's not entirely necessary.You may prefer to create a script locally and then upload to your Cloud Shell using the Upload feature in the Cloud Shell toolbar. New and helpful commands:Opening or creating a file with VI: vi filenameClosing a file in VI: Press ESC > q > enter (separately, in this order)Saving a file in VI: Press ESC > w > enter (separately, in this order)Exiting without saving: Press ESC > w! > enter (separately, this order)Making a file executable: chmod +x fileListing all files: ls -la or lsExecuting a file: /path/to/file.sh All commands used if you wish to follow along:

vi script1.sh
chmod +x script1.sh
ls -la
clear
./script1.sh
script1.sh:
#!/bin/bash

timeStamp=$(date)

echo "Hello awesome students!"
echo "The time is: ${timeStamp}"
echo "Let's take a look at our resource groups"

az group list -o table

Scripted Deployments with Azure CLI and Bash

00:08:45

Lesson Description:

Continuing on from our Getting Started lesson, we now take a look at a real-world scenario and script. In this lesson, we step through an example scenario for deploying infrastructure in Azure, breaking down a script into steps, and looking at a complete script. This lesson demonstrates how we combine various concepts from this course into a fully functional script. All commands used if you wish to follow along:

vi scriptDeploy.sh
chmod +x scriptDeploy.sh
./scriptDeploy.sh
scriptDeploy.sh
#!/bin/bash

declare -A project

# Ask for the name of the book
echo -n "Enter the name of the book, and press [ENTER]: "
read projectName

# Create all the resource names based on the book name
project[name]=$projectName
project[rgName]="${projectName}-rg"
project[vnetName]="${projectName}-vnet"

# Storage Accounts cannot be uppercase (or greater than 24 characters)
randString=$(date +%s | sha256sum | base64 | head -c 6)
saTempName="${projectName}store1${randString}"
project[saName]=$(echo $saTempName | awk '{print tolower($0)}')

# Let's display the information we've generated so far
echo "--------------"
echo "We are going to setup some infrastructure using the following values"
echo "Project Name: ${project[name]}"
echo "> RG Name: ${project[rgName]}"
echo "> VNet Name: ${project[vnetName]}"
echo "> Storage Account Name: ${project[saName]}"
echo ""
echo ""

# Let's get started creating the resources
echo "Creating the Resource Group"
az group create -n ${project[rgName]} -l "Australia Southeast"

echo "Creating the Virtual Network"
az network vnet create -n ${project[vnetName]} -g ${project[rgName]}

echo "Creating the Storage Account"
az storage account create -n ${project[saName]} -g ${project[rgName]}

Take this course and learn a new skill today.

Transform your learning with our all access plan.

Start 7-Day Free Trial