1
votes

I have the following provider configured in terraform:

provider "google" {
  credentials = "${file("key.json")}"
  project     = "project-123456"
  region      = "${var.region}"
}

I was able to move the project name to a variable that I pass in when calling terraform plan and apply. But the credential key file doesn't seem to be configurable.

provider "google" {
  credentials = "${var.key}"
  project     = "${var.project}"
  region      = "${var.region}"
}

terraform plan -var key='${file("key.json")}' -var project=project-123456

Throws this error:

  • provider.google: credentials are not valid JSON '${file("key.json")}': invalid character '$' looking for beginning of value

I also tried like this:

provider "google" {
  credentials = "${file(${var.key})}"
  project     = "${var.project}"
  region      = "${var.region}"
}

terraform plan -var key=key.json -var project=project-123456

But it throws this error:

Error reading config for provider config google: parse error at 1:8: expected expression but found invalid sequence "$"

How can I configure the credentials file for a provider?

1

1 Answers

1
votes

I guessed it! Just need some extra quotes in my last attempt:

credentials = "${file(${var.key})}"

credentials = "${file("${var.key}")}"

terraform plan -var key=key.json -var project=project-123456