Terraform

Terraform in Google Cloud

Tip

You have already install the terraform client and your user logged in the Cloud Shell.

Tip

You can get all the resources of a project in HCL (terraform lang) with this command gcloud beta resource-config bulk-export --project=PROJECT_ID --resource-format=terraform

main.tf

terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
      version = "3.5.0"
    }
  }
  backend "gcs" {
    bucket  = "tf-state-prod"
    prefix  = "terraform/state"
  }
}

provider "google" {
  credentials = file("<NAME>.json")

  project = "<PROJECT_ID>"
  region  = "us-central1"
  zone    = "us-central1-c"
}

resource "google_compute_network" "vpc_network" {
  name = "terraform-network"
}

GCS backend for status

terraform {
  backend "gcs" {
    bucket  = "tf-state-prod"
    prefix  = "terraform/state"
  }
}