Pallab
Pallab

Reputation: 2333

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.

Upvotes: 0

Views: 580

Answers (2)

Cloudlady
Cloudlady

Reputation: 773

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

Upvotes: 0

user2314737
user2314737

Reputation: 29407

Since the backslash (\) is an escape character in Terraform, you need to escape it by prepending another backslash.

\\ Literal backslash

Change path to: credentials = "C:\\Users\\xxx\\Downloads\\credentials.json"

See: https://developer.hashicorp.com/terraform/language/expressions/strings#escape-sequences

Upvotes: 0

Related Questions