Getting an Environment Variable in Terraform configuration?

I would try something more like this, which seems closer to the documentation.

variable "UN" {
  type = string
}

variable "PW" {
  type = string
}

resource "google_container_cluster" "primary" {
  name = "marcellus-wallace"
  zone = "us-central1-a"
  initial_node_count = 3

  master_auth {
    username = var.UN
    password = var.PW
  }

  node_config {
    oauth_scopes = [
        "https://www.googleapis.com/auth/compute",
        "https://www.googleapis.com/auth/devstorage.read_only",
        "https://www.googleapis.com/auth/logging.write",
        "https://www.googleapis.com/auth/monitoring"
    ]
  }
}

With the CLI command being the below.

TF_VAR_UN=foo TF_VAR_PW=bar terraform apply

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)