Configure a Terraform Remote Backend in Google Cloud

This blog post will demonstrate how to set up Terraform remote state and storage on GCP using a step-by-step guide.

Terraform’s remote state allows us to retain and maintain the state of our infrastructure from multiple devices and services and even collaborate with team members.

When working with GCP, we can maintain the state of our infrastructure deployment in a GCP bucket and use it with Azure Pipelines when deploying infrastructure to GCP.

Remote State

To get started with our GCP terraform remote state, we need to ensure its prerequisites are met. Before you start, make sure you have the following.

  • Download and install the Google Cloud CLI for your operating system.
  • Terraform is installed on your machine.

Google Cloud CLI Setup

Create a Storage Bucket for Remote State

Before deploying the storage bucket, run the following gcloud command to authenticate to GCP.

After authenticating successfully, run the following commands.

Use Remote State

To use the GCP remote state in another terraform configuration. Add the following code to your config.

A full configuration file that uses a GCP remote state looks like this.

To change your terraform remote state from local to GCP, run

Success! You're on the list.

Leave a Comment

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