How to Deploy a CentOS Linux VM Instance in GCP using Terraform

Guillermo Musumeci
4 min readFeb 24, 2022

In this story, we will learn how to deploy a CentOS Linux VM Instance (VM) in GCP (Google Cloud Platform) using Terraform.

Prerequisite: GCP Credentials

Before creating our GCP VM Instances, we will need GCP Credentials to execute our Terraform code.

Please refer to the “How to Create a Service Account for Terraform in GCP (Google Cloud Platform)” story if you need help to create the credentials.

Note: Using private key .json files are great for learning and testing however they are not recommended in production environments. Never push private keys files to code repositories.

Creating a Terraform file for GCP Authentication

First, we create a file called “provider-variables.tf”, used by the GCP authentication variables, and add the following code to the file.

We will need a GCP Project Name, a GCP Region, and a .JSON file name with the private keys to authenticate to GCP.

# GCP authentication file
variable "gcp_auth_file" {
type = string
description = "GCP authentication file"
}
# define GCP region
variable "gcp_region" {
type = string
description = "GCP region"…

--

--

Guillermo Musumeci

Certified AWS, Azure & GCP Architect | HashiCorp Ambassador | Terraform SME | KopiCloud Founder | ex-AWS | Entrepreneur | Book Author | Husband & Dad of ✌