Terraform CFT for GCP

Vaishnavi A
2 min readJun 3, 2021

--

Hello Everyone,

Recently, while working on Terraform one of my seniors suggested revamping our existing Terraform code. And had asked us to use Terraform CFT Modules provided by Google to create resources on GCP. I was very much intrigued by this concept, as it made our lives very much easier.

What is CFT?

CFT stands for “Cloud Foundation Toolkit”. CFT provides ready-made templates to create complex infrastructure on GCP in no time!! Just kidding ;)

I mean some effort is definitely needed. But the best part here is that we can create GCP resources without using the “resource” block in our Terraform codes. Using CFT, one can design their Terraform modules as per the requirement with customized input and output variables.

Lets check it out with an example:

In this example, I will be creating a GCS Bucket on the defined GCP project.
We can start with creating a folder with 3 files — main.tf, vars.tf, and terraform.auto.tfvars

This is the main.tf file 
module "test_bucket" {
source = "terraform-google-modules/cloud-storage/google//modules/simple_bucket"
name = var.name
project_id = var.project_id
location = var.location
}

Next, will be our vars.tf file

variable "name" {
description = "Bucket Name"
type = string
}
variable "location" {
description = "Bucket Location"
type = string
}
variable "project_id" {
description = "Bucket Project ID"
type = string
}

And then is the terraform.auto.tfvars file to define our input values.

name       = "test_cft_bucket"
location = "us-central1"
project_id = "my_project_id" #define your Project ID here

Once we have add all 3 files , we can run the 3 magic commands of Terraform:
1. terraform init

2. terraform plan

3. terraform apply

And then the GCS Bucket is deployed on the defined GCP Project.

Important points to note:
1.
You may find multiple CFT modules available for the same GCP resource such as Google Compute VM. It is completely upto you which module you want to use.
2. Also for every CFT module you use, there maybe a set of required input variables.
3. And you can find CFT modules on GitHub or browse them over Terraform Registry.

References:

  1. https://github.com/terraform-google-modules
  2. https://registry.terraform.io/modules/terraform-google-modules/cloud-storage/google/latest/submodules/simple_bucket
  3. https://registry.terraform.io/browse/modules

--

--

No responses yet