Introduction

Recently I created an app config-service that fetches the config data from Google Sheet. This app was deployed using GCP serverless services Cloud Source RepositoryCloud BuildContainer Registry, and Cloud Run.

In this article, we will see how to automate this CI/CD pipeline using Terraform.

Setup

In order to complete this guide, you’ll need to install the following tools

  • Terraform: This guide uses Terraform to deploy resources.
  • Git: Git is used to clone the example code and trigger new deployments.
  • GCP: You will need a GCP account with billing enabled.

Create GCP Project

Create a GCP project for this tutorial.

Create Service Account

  • Create Service Account.
  • Assign the roles: Editor, Security Admin, Service Usage Consumer and Source Repository Administrator.
  • Download the key and renamed it as terraform-key.json

Enable the Cloud Resource Manager API

Everything is setup now. Let the wheels roll !!


Deploy the GCP serverless resources using Terraform

Clone the following repository containing the sample code, then switch to the terraform directory:

$ git clone  https://github.com/vikramshinde12/config-service-googlesheet.git

$ cd  config-service-googlesheet/terraform

Next, copy the terrform.tfvars.example file to terraform.tfvars. You will need to replace the value of the project variables.

Then, copy the service account key terraform-key.json to this folder.

Execute following command to set Google Credentials.

$ export GOOGLE_CLOUD_KEYFILE_JSON=terraform-key.json

Execute Terraform scripts

First initialize the Terraform.

$ terraform init

Image for post

Image for post

Initializing Terraform

$ terraform plan

Image for post

#automation #terraform #google-cloud-platform #google-cloud-run #devops

Deploy CI/CD pipeline on GCP using Terraform
9.00 GEEK