I’ve been trying to connect GCP with Terraform Cloud’s variables, but it hasn’t worked so far and I receive error messages saying that the variable I am referencing is not in the root.
So I’ve moved the variable outside of the Provider to try to declare it but it doesn’t take either.
I’ve re-created the variable set in Terraform cloud about three times now and I still receive the error message so I’m unsure as to how I can reference variables in Terraform cloud with my main.tf file.
The code I have written is:
variable "TF_VAR_gcp_credentials" {
}
provider "google" {
project = "terraform-cloud-gcp-demo"
credentials = files(var.TF_VAR_gcp_credentials)
region = "us-central1"
zone = "us-central1-c"
}
resource "google_compute_instance" "vm_instance" {
name = "terraform-instance"
machine_type = "f1-micro"
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
network = "default"
access_config {
}
}
}
Additionally, the variable set has the json file within it so I’m unsure if this might be causing the issue and if so, then how can I use a service account within Terrafrom Cloud without exposing the service account credentials?