Project: Azure Resources

Project to give you the hands-on practice of the Azure resource group.

Project overview

This chapter project will build each component one at a time using the Azure CLI inside the Azure Cloud Shell.

Using the Azure Cloud Shell isn’t required to use the Azure CLI, but it will be the preferred method used throughout this course.

Through a PowerShell script running Azure CLI commands, you will build the following components:

  • A resource group.

  • A public IP address.

  • A virtual network (vNet) and subnet for all components to share.

  • A network security group (NSG) and rules to protect the application.

  • An Azure Load Balancer with a frontend IP pool and backend IP address pool.

  • A load balancer rule to direct HTTP traffic to the website.

  • A VM availability set with three VMs.

  • A custom script extension installed on the VMs to run PowerShell scripts.

  • A simple IIS website deployed to all VMs.

Preparing to build the Azure resources

Let’s start out by setting up the script for Azure resource-building. First, define a few initial variables. When you’re going to be building a PowerShell script that performs tasks using the same values, it’s a good idea to define variables. Using variables, you can reference the same value over and over in a script and only need to make one change if that value changes over time.

For this script, define three variables as shown below. You’ll see these variables pop up from time to time as you progress through building the script.

export projectName='NoBSAzureLb'
export resourceGroupName=$projectName
export location='eastus'

You’ll also see throughout the script that nearly all Azure CLI commands require a resource group. Instead of typing --resource-group $resourceGroupName over and over, you can set a default resource group in Azure CLI. Run the following code snippet. This snippet will configure the Azure CLI to always default to the NoBSAzureLb resource group for all actions if no resource group is defined.

az configure --defaults "resource-group=$resourceGroupName"

Resource group

Next, all resources you’ll create in this project will be in a single resource group. Placing all resources in a single group allows you to easily clean up all resources created in this project at the end.

az group create --name $resourceGroupName --location $location

Public IP address

This Azure load balancer you will create will be a public load balancer exposed to the Internet. Because it’s exposed to the Internet, you will need to assign a public IP address to it. The following code snippet creates a public IP with a static IP called NoBSAzure-Lb. A static IP isn’t necessary but is easiest to manage because you don’t have to worry about the IP changing on you.

export pipName="$projectName-pip" 
az network public-ip create -g $resourceGroupName --name $pipName --allocation-method Static

Try it yourself!

Press the Run button and practice all these commands yourself after providing the environment variables.

Get hands-on with 1000+ tech skills courses.