Using Terraform with Azure

15 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Hey, Gurus! Welcome to the Using Terraform with Azure hands-on lab.

In this lab, we will cover 3 objectives. First, we will log into the Azure portal and configure the Cloud Shell to use Bash. Second, we check which version of Terraform the Cloud Shell is running. If it is not the latest version, we will update it. In our final objective, we configure Terraform to use the Terraform Azure provider.

Instead of jumping around to different screens, this is a quick and easy way to use Terraform with Azure.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Setup Cloud Shell

In the portal

  1. Go to the 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 Attach Storage.
Check the Terraform Version

In the Cloud Shell

  1. Check the Terraform version in the Cloud Shell.
  2. If the Terraform version is up to date, proceed to the next objective. If it is out of date, follow the steps below.
  3. Download the updated Terraform binary from the lab repo to the Cloud Shell.
  4. Unzip the file.
  5. Create a directory called bin.
  6. Move the terraform binary to the bin directory.
  7. Check the Terraform version to confirm you are using the newest version available.
Configure Terraform Azure Provider

In the Cloud Shell

  1. Create a working directory called terraformguru.
  2. Move into the terraformguru working directory.
  3. Create a file called
  4. Paste the following code into the file:

    terraform {
      required_providers {
        azurerm = {
          source  = "hashicorp/azurerm"
          version = "=2.91.0"
    provider "azurerm" {
      features {}
      skip_provider_registration = true
  5. Save the file.
  6. Initialize your working directory.

Additional Resources

Picture this…

You decide you want to use Terraform to start managing your Azure infrastructure. You’ve got the Azure Portal pulled up in your browser. You log in to the portal and want to use Terraform to deploy some resources, but you don’t want to spend too much time getting things set up on your machine. You spend some time thinking, and you remember that Terraform is "baked" into the Azure Cloud Shell. You open the Cloud Shell and, since you are a Linux guru, decide to use Bash for the shell. You create a directory called "terraformguru" where you start trying out Terraform to deploy your resources. You start off by configuring Terraform to use the Azure provider so Terraform can communicate with the Azure APIs. You create a configuration file called "" in the terraformguru directory with your Azure provider information. Afterward, you initialize the working directory to pull down those provider plugins, and you are ready to start building your configuration to deploy your infrastructure resources. So, 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?