hands-on lab

Provisioning an Azure VM with Terraform Modules

Difficulty: Advanced
Duration: Up to 1 hour and 30 minutes
Students: 2,215
Rating: 4.4/5
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.

Description

Terraform by HashiCorp can manage your infrastructure across multiple cloud providers and on-prem. To reuse and share components across projects and to better organize large projects, you can create modules. In this lab, you will use modules shared on the public Terraform Registry as well as a module that you create to provision a web server virtual machine in Azure. The lab will introduce you to using Cloud Academy's browser-based IDE as you use it to complete the lab.

Lab Objectives

Upon completion of this lab you will be able to:

  • Create reusable Terraform modules
  • Use Terraform modules shared on the Terraform Registry
  • Work with Terraform Data Sources
  • Use Terraform Provisioners to bootstrap VMs

Lab Prerequisites

You should be familiar with:

  • Working at the command-line in Linux
  • Terraform basics

The following labs can be used to fulfill the prerequisites to this lab:

Lab Environment

Before completing the lab instructions, the environment will look as follows:

After completing the lab instructions, the environment should look similar to:

Updates

May 3rd, 2023 - Updated theia to enable autosave

November 18th, 2021 - Converted lab to use browser-based IDE to avoid Azure Cloud Shell instability issues, updated to newer Terraform version

December 23rd, 2020 - Upgraded the VM SKU used in the lab

May 13th, 2020 - Updated a validation check function to more accurately reflect whether a student has met a condition

Sept. 20th, 2019 - Resolved an issue that caused end of lab validation check to fail to complete

Sept. 6th, 2019 - Updated to the latest version of Terraform in Azure Cloud Shell, and resolved an issue causing an error in the VM provisioning phase

June 26th, 2019 - Updated all instructions and images to match the latest Terraform and Azure Cloud Shell experience

May 6th, 2019 - Added lab validation lab Step to check the work performed in the lab

May 6th, 2019 - Fixed an issue with the latest AzureRM Terraform provider attempting to register unnecessary Resource Providers and updated screenshots to reflect the latest experience

September 7, 2018 - Updated images to improve lab experience

Covered topics

Lab steps

Logging into Azure using Azure CLI
Initializing Terraform with the Azure Provider
Setting Up a Data Source to Reference the Lab Resource Group
Using a VNet Module from the Terraform Registry
Using a Security Module from the Terraform Registry
Creating a Local Module for Provisioning Azure VMs
Provisioning an Azure VM with the Local Terraform Module