hands-on lab

Integrating Conditional Logic into Terraform Configurations

Difficulty: Intermediate
Duration: Up to 45 minutes
Students: 2,870
Rating: 5/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

As companies start to build infrastructure using Terraform, the logic required to build self-service automation becomes complex. That's why HCL (HashiCorp Configuration Language) contains expressions that can perform calculations within Terraform configurations. Integrating conditional logic into modules allows them to become dynamic and reusable for different scenarios. 

In this lab, you will create an EC2 Module that contains conditional logic for deploying an EC2 Instance. 

Learning objectives

Upon completion of this lab, you will be able to:

  • Understand how Terraform modules can be made dynamic for reusability
  • Learn about using conditional expressions within Terraform configurations

Intended audience

  • Individuals studying to take the HashiCorp Certified: Terraform Associate exam
  • Anyone interested in learning how to use Terraform to manage Cloud Service Providers

Prerequisites

You should be familiar with:

  • Cloud Services
  • DevOps
  • Basic understanding of Terraform modules and variables

The following course and lab can be used to fulfill the prerequisites:

Updates

December 22nd, 2023 - Lab updated to utilize CodeTour IDE

April 24th, 2023 - Resolved IDE delay

Environment before

Environment after

Covered topics

Lab steps

Create Terraform Configuration with Conditional Logic