How to Deploy a CentOS Linux VM Instance in GCP using Terraform
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"…