Deploy GCP Infrastructure Using Terraform and Azure DevOps Pipelines

In this Google Cloud (GCP) and Azure Pipelines, we will show how to deploy infrastructure to GCP using Terraform from an Azure Pipeline.

Azure DevOps pipeline integrates with many cloud services, and GCP is one of them. The process of deploying infrastructure and getting the integration into the work is:

  • Create a GCP project
  • Create a GCP Service account
  • Create and export private security key
  • Create an Azure DevOps service connection
  • Create pipeline and deploy infrastructure

The first step in integrating Azure Pipelines and GCP is to create a service account.

Create Service Account

To create a GCP Service account, use the following steps.

  • Create or use an existing GCP project
  • Create a new service account by t
  • Open the GCP console
  • Select the new Project.
  • From the Navigation Menu, select IAM & Admin
  • Click on Service Accounts
  • Click on Create New Service Account
  • Name the Service account, click on Save, and continue
  • Select the Owner role and click on Continue
  • Click on Manage Keys (Action menu) to create a JSON credential file
  • Click on Add Key
  • Select Create a new key
  • Save the JSON file to your local system

Below is a screenshot of the Add Key screen.

Once you have the JSON security file, review it as you need the following items.

  • Project ID
  • Client email
  • Token URI
  • Private Key (When copying the key, you need to include -----BEGIN PRIVATE KEY-----private key value---END PRIVATE KEY-----

Create a Service Connection to GCP

To create a Service Connection to GCP in Azure DevOps follow the steps below.

  1. Click on Project Settings from the Azure DevOps project that is used for GCP deployment
  2. Click on Service Connections
  3. Click on New Service Connection
  4. Search for GCP for Terraform
  5. Fill in the information Using the downloaded JSON file from the previous step.

Make sure to tick the Grant access permissions to all pipelines.

You have a service account and a service connection to GCP at this stage. We need to create an Azure Pipeline to deploy infrastructure to GCP.

For our Project, we need to set up a storage account on GCP. To do this, we are using a terraform configuration file that manages the deployment. Additionally, we have a YAML pipeline that utilizes the Terraform extension for Azure DevOps. The following code is used in the pipeline.

Azure Pipeline (YAML)

Before is the YAML pipeline that deploys the terraform configuration file (see below).

Below is the Terraform configuration file that deploys the infrastructure.

Note: The configuration uses a remote state file which is optional.

Terraform Configuration

Success! You're on the list.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.