Skip to main content

Terraform Notes

Template for Terraform GCP config file?
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
}
How to get terraform outputs?
# need to declare an output block:
output "instance_name" {
  description = "The name of the database instance"
  value       = google_sql_database_instance.db_main.name
}

# then on command line:

$ terraform output
$ terraform output -json