Search code examples
google-cloud-platformterraformterraform-provider-gcp

Authenticating to GCP Using Terraform Cloud and Google Provider


I have the below code for provisioning a GCS bucket in my GCP project

I am using Terraform Cloud and i have authenticated using Application Default credentials to GCP I have created an env variable in TF Cloud with the below values :

GOOGLE_CLOUD_KEYFILE_JSON = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"

My Terraform Code is provided below :

provider "google" {
  project     = "strange-flame-167811"
  region      = "us-east1"
  credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
}


resource "google_storage_bucket" "test" {
  name     = "my-project-id-test-bucket"
  location = "us-east1"
}

When i run Terraform plan i get these errors below:

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Error: Invalid escape sequence
│ 
│   on main.tf line 4, in provider "google":
│    4:   credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
│ 
│ The \U escape sequence must be followed by eight hexadecimal digits.
╵

╷
│ Error: Invalid escape sequence
│ 
│   on main.tf line 4, in provider "google":
│    4:   credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
│ 
│ The symbol "p" is not a valid escape sequence selector.
╵

╷
│ Error: Invalid escape sequence
│ 
│   on main.tf line 4, in provider "google":
│    4:   credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
│ 
│ The symbol "D" is not a valid escape sequence selector.
╵

╷
│ Error: Invalid escape sequence
│ 
│   on main.tf line 4, in provider "google":
│    4:   credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
│ 
│ The symbol "s" is not a valid escape sequence selector.

Solution

  • You need to call out the credentials as a file: credentials = file(".json")