Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Labs

Automating Deployments to GCP with Terraform

You are a DevOps engineer at a company that is moving to automated deployments using Infrastructure as Code (IaC). The organization has embraced Terraform modules to develop reusable solutions, and wants to leverage common modules across environments to maintain consistency. You will need to set up a solution using Source Repositories and Cloud Build to automate the deployment of infrastructure using Terraform. The solution will need to support development and production branches and deploy separate infrastructure for each branch. That way, changes can be promoted from development to production entirely in version control.

Lab platform
Lab Info
Level
Advanced
Last updated
Sep 23, 2025
Duration
1h 30m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Set Up a Cloud Source Repository (CSR) with the Terraform Code to Create a ‘dev’ Environment
    • Enable Source Repos and Cloud Build: gcloud services enable sourcerepo.googleapis.com cloudbuild.googleapis.com iam.googleapis.com
    • Create a bucket to store your project's state: gsutil mb gs://<PROJECT ID>
    • Create a repository: gcloud source repos create ci-app
    • Check out the repo: gcloud source repos clone ci-app
    • Open the repo: cd ci-app
    • Create a dev branch: git checkout -b dev
    • Create modules/web and cd into the directory
    • Copy the module code into the web directory: wget https://raw.githubusercontent.com/ACloudGuru-Resources/content-advanced-terraform-with-gcp/main/automation_lab/main.tf
    • Copy the template code into the web directory: wget https://raw.githubusercontent.com/ACloudGuru-Resources/content-advanced-terraform-with-gcp/main/automation_lab/index.html
    • In the ci-app directory, create a dev directory with a main.tf file
    • Add a terraform block to dev/main.tf, setting the backend to the bucket you created
    • Create a web_app module from the module directory — be sure to set the env variable, and set an output for the host IP
    • In the ci-app directory, copy the cloudbuid.yaml file with: wget https://raw.githubusercontent.com/ACloudGuru-Resources/content-advanced-terraform-with-gcp/main/automation_lab/cloudbuild.yaml
    • Set your git configuration: git config --global user.email "[email protected]" and git config --global user.name "Wes"
    • Commit the code with: git add --a and git commit -m 'added module code'
    • Push the code to the CSR: git push --set-upstream origin dev
  2. Challenge

    Configure a Cloud Build Trigger Connected to the CSR
    • In the GCP console, go to Cloud Build
    • Click on Triggers in the left column
    • Create a trigger
    • Run the trigger to deploy the dev infrastructure
    • Go to the IP output by the build run
  3. Challenge

    Add a Branch and Configuration File to Create Infrastructure in the ‘prod’ Environment
    • In Cloud Shell, create a prod directory
    • Create prod/main.tf. Create a web_app module from the module directory — be sure to set the env variable, and set an output for the host IP
    • Commit and push the new code to a new upstream branch: origin/prod
    • View the build logs in the console
    • Go to the IP output by the build run
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

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.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight