Skip to main content

Terraform Notes

Template for GCP?

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "4.51.0"
    }
  }
}

provide "google" {
  project = "logan-dev1"
}

resource ... 

How to declare a variable in terraform?

variable "create_lb1" {
  type    = bool
  default = true
}

Diff between locals and variables?

Scope: locals are local, variables are global
Mutability: locals are declared onced and immutable, variables are mutable

Diff between google and google-beta providers?

In short, using google-beta over google is similar to using gcloud beta over gcloud. Features that are exclusively available in google-beta are GCP features that are not yet GA, and they will be made available in google after they go to GA.

Example for locals?

locals {
  create_lb1         = var.should_load
  create_api_gateway = true
}