Creating Reusable Infrastructure with Terraform Modules in GCP

Lab Steps

lock
Activating the Google Cloud Platform Service Account
lock
Creating a Terraform Module in GCP

The hands-on lab is part of this learning path

Ready for the real environment experience?

DifficultyBeginner
Time Limit30m
Students60
Ratings
5/5
starstarstarstarstar

Description

Terraform modules are a critical component of production-grade Terraform configurations. Modules give infrastructure developers the ability to organize services into logical, reusable components. For example, you can create a module for deploying Google Cloud Compute Engine instances and a module for deploying pre-configured Cloud Storage buckets. Each of these modules could then be used to implement common infrastructure patterns with less time spent on configurations.

Terraform configuration files that are thousands of lines of code are considered an anti-pattern. Once infrastructure code grows to a certain size and becomes unmanageable, execution plans may take over 10 minutes to complete. Instead of this monolithic approach, splitting the resource configurations up into modules can provide reusable, easy-to-test resource units.

Modules also provide a way for the community to share Terraform configurations with others. The Terraform Registry hosts thousands of available Terraform resource modules that can be used to deploy common infrastructure configurations. It is highly recommended to refer to existing modules in this registry before creating your own from scratch.

In this lab, you will learn how to configure a GCE instance module in a local Terraform project and explore the benefits of this pattern of reusable, modular infrastructure.

Learning Objectives

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

  • Configure Terraform modules for GCP resources
  • Pass data into and between Terraform modules

Intended Audience

  • Individuals looking to pass the HashiCorp Certified: Terraform Associate Exam
  • Individuals and teams seeking an introduction to using Terraform with Google Cloud Platform

Prerequisites

Familiarity with the following will be beneficial but is not required:

  • Basic concepts of Google Cloud Platform
  • Configuring Terraform variables

The following lab can be used to fulfill the prerequisites:

Environment before
PREVIEW
arrow_forward
Environment after
PREVIEW
About the Author
Students17130
Labs51
Learning paths4

Jun is a Cloud Labs Developer with previous experience as a Software Engineer and Cloud Developer. He holds the AWS Certified Solutions Architect and DevOps Engineer Professional certifications. He also holds the AWS Certified Solutions Architect, Developer, and SysOps Administrator Associate certifications. 

Jun is focused on giving back to the growing cloud community by sharing his knowledge and experience with students and creating engaging content.