Testing Terraform Code with Terratest

Lab Steps

lock
Writing a Test with Terratest

The hands-on lab is part of these learning paths

DevSecOps - Build and Release Secure Software Faster
course-steps
8
certification
1
lab-steps
12
description
3

Ready for the real environment experience?

DifficultyAdvanced
Time Limit40m
Students112
Ratings
5/5
starstarstarstarstar

Description

Testing code is a common software development practice. Developers validate pieces of their code in an automated fashion to ensure it is working as expected. The new age of infrastructure development adopts this best practice to manage and maintain infrastructure code. Because of the fast pace development of Cloud Service Providers, infrastructure code rots quickly. The same code used to deploy an EC2 instance has a good chance of not working in 6 months if not kept up to date. Writing tests for Terraform code validates modules are always working as expected. It also provides faster feedback allowing quick changes to modules with confidence that they won't break the infrastructure using them in production. Terratest is an open-source Golang library used for testing Terraform and is quickly rising in popularity.

In this lab, you will write a test for a Terraform module using the Terratest GO library.

Learning Objectives

Upon completion of this lab you will be able to:

  • Understand how to write a test for a Terraform module
  • Learn how test files work in Golang

Intended Audience

This lab is intended for:

  • Individuals familiar with using Terraform and how to deploy resources
  • Anyone interested in learning how to use Terragrunt to increase Terraform effectiveness
  • Enterprises looking to scale their Terraform codebase

Lab Prerequisites

You should be familiar with:

  • Cloud Services
  • DevOps
  • Terraform

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

Updates

February 22nd, 2021 - Pin the terratest version to avoid an issue in newer releases

Environment before
PREVIEW
arrow_forward
Environment after
PREVIEW
About the Author
Students2825
Labs42
Courses1
Learning paths3

Luke currently serves as a Cloud Labs Developer at Cloud Academy. His background is infrastructure development using Terraform. He is an Azure DevOps Engineer Expert, Azure Administrator Associate, and HashiCorp Certified - Terraform Associate.

Covered Topics