Create a VM Scale Set in Azure with Terraform

45 minutes
  • 5 Learning Objectives

About this Hands-on Lab

Hey, Gurus! Welcome to the Create a VM Scale Set in Azure with Terraform lab. In this lab, we will cover these 4 objectives:

1. First, we will log into the Azure Portal, configure the Cloud Shell, and download and run the lab setup script to setup the lab.
1. Second, we will import the resource group.
1. Third, we will add our VM scale set to our configuration and set CPU thresholds to allow for autoscaling.
1. And for the fourth objective, we will add a jumpbox to our configuration to give us a server to connect to that we can use to connect to our cluster. We will then deploy our VM cluster resources.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Set Up Cloud Shell and the Lab Environment

In the Portal

  1. Go to the Azure Portal and log in using your lab credentials.
  2. Click the Cloud Shell icon next to the search bar in the Portal.
  3. Select Bash at the prompt.
  4. Click Show advanced settings.
  5. Set the Cloud Shell region to the same location as the resource group.
  6. Select the existing Resource group, and select Use Existing for the Storage account.
  7. In the File share section, choose Create new and enter "terraform".
  8. Click Create storage.
  9. Download the script at
  10. Add execute permissions to the script.
  11. Run the script.
Import the Resource Group into Terraform

In the Cloud Shell

  1. In the Cloud Shell, review the
  2. Make note of the resource group name and label at the top and then close the file.
  3. Run the az group list command to get the subscription id.
  4. Import your resource group into Terraform using the resource name, label, and subscription id.
  5. After the import, add the name and location of your resource group to the file so it looks like the code below (fill in with your resource group and location):
    resource "azurerm_resource_group" "guru" {
        name     = "<RESOURCE_GROUP>"
        location = "<LOCATION>"
  6. Save the file.
Define the Azure VM Scale Set

In the Cloud Shell

  1. Create a file called file.
  2. Define the vm scale set configuration so it will deply a 2 vm cluster.
  3. Use variables to define the location, admin_username, admin_password, and tags.
  4. Make sure you associate your scale set with your subnet and load balancer backend pool in the file.
  5. Save the changes.
Define the Jumpbox Configuration

In the Cloud Shell

  1. Create a file called file.
  2. Define the jumpbox vm configuration.
  3. Use variables to define the location, admin_username, admin_password, and tags..
  4. Make sure you create a network interface and a public ip for your jumpbox.
  5. Save the changes.
Create the Variables and Outputs, then Deploy

In the Cloud Shell

1) Create the file and define these variables:
a) location
b) tags
c) application port (used in the file)
d) admin_user
e) admin_password
2) Create the file and define these output variables:
a) vmss_public_ip_fqdn
b) jumpbox_public_ip_fqdn
c) jumpbox_public_ip
3) Create the web.conf file and add the Nginx package to the config. This will configure your cluster to run Nginx.
4) Save both files and apply your configuration.
5) Confirm you have successfull deployed your resources and you can interact with your cluster.

Additional Resources

So picture this…

You are being asked to start building out an app server cluster for a comic reader that you are working on for your employer for digital comics. You have built this cluster but realized an autoscaling app server cluster would be more beneficial and efficient. You will use Terraform to build out a VM scale set that will key in on CPU usage and set up thresholds to allow your cluster to autoscale on CPU load. You will also need to create a jumpbox to allow you to connect to your cluster for management and troubleshooting. You have a resource group that has been deployed that you will be using. Import your resource group, build out your Terraform configuration, and then deploy your VM cluster resources with Terraform to Azure.

Now that we have a plan, let’s put it into action!

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?