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

Using Terraform to Launch a Compute Engine Instance in GCP

Learning how to create major resources with Terraform is important in understanding how Terraform works with GCP. In this hands-on lab, we will walk through what creating a Compute Engine instance looks like and how to configure it.

Lab platform
Lab Info
Level
Intermediate
Last updated
Aug 20, 2025
Duration
1h 15m

Contact sales

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

    Create a Service Account
    1. From Google Cloud console's main navigation, choose IAM & Admin > Service Accounts.
    2. Click Create service account.
    3. Give your service account a name.
    4. Click Create.
    5. In the roles dropdown, select Project > Owner.
    6. Click Continue and then Done.
  2. Challenge

    Log in to the Host Instance and Ensure Terraform Is Installed
    1. From Google Cloud navigation, choose Compute Engine > VM instances.

    2. Click SSH next to terraform-instance.

    3. Use root privileges:

      sudo -i
      
    4. Change into the root directory:

      cd /
      
    5. Call Terraform:

      terraform
      
  3. Challenge

    Create a Service Account Key within the Instance
    1. Allow the SDK to communicate with GCP:

      gcloud init --console-only
      
    2. Enter Y and Yat the prompt.

    3. Choose your Cloud Project.

    4. Select the Cloud Student account.

    5. Choose Y to configure a default Compute Region and Zone

    6. Choose "us-central1-c"

    7. Copy the code provided.

    8. Paste the code into the terminal.

    9. Create the service account key:

      gcloud iam service-accounts keys create /downloads/compute-instance.json --iam-account <SERVICE_ACCOUNT_EMAIL>
      
  4. Challenge

    Create and Deploy the Configuration File
    1. Create a main.tf file:

      vim main.tf
      
    2. Paste the following configuration, replacing <PROJECT_NAME> with your project name (found in the top navigation bar of the Google Cloud console):

      provider "google" {
        version = "3.20.0"
        credentials = file("/downloads/compute-instance.json")
        project = "<PROJECT_NAME>"
        region  = "us-central1"
        zone    = "us-central1-c"
      }
      
      resource "google_compute_network" "vpc_network" {
        name = "terraform-network"
      }
      resource "google_compute_instance" "vm_instance" {
        name         = "terraform-instance2"
        machine_type = "f1-micro"
        zone         = "us-central1-c"
        boot_disk {
          initialize_params {
            image = "centos-cloud/centos-stream-9"
          }
        }
      
        network_interface {
          network = google_compute_network.vpc_network.name
          access_config {
          }
        }
      }
      
    3. Save and exit the file by pressing Escape followed by :wq.

    4. Finish up by running terraform init, terraform validate, terraform plan, and terraform apply.

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