Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google cloud provider environment variables not read as file as expected #8493

Closed
pvanderlinden opened this issue Aug 26, 2016 · 4 comments
Closed

Comments

@pvanderlinden
Copy link

If you set any of the environment variables as specified in the Google cloud provider documentation, the file is not actually read, but tries to parse the filename as JSON. (GOOGLE_CREDENTIALS, GOOGLE_CLOUD_KEYFILE_JSON, GCLOUD_KEYFILE_JSON, see https://www.terraform.io/docs/providers/google/index.html#credentials)

Example:

$ terraform plan
There are warnings and/or errors related to your configuration. Please
fix these before continuing.

Errors:

  * provider.google: credentials are not valid JSON '/home/me/.gcloud/credentials.json': invalid character '/' looking for beginning of value

Terraform version: 0.7.2

@cblecker
Copy link
Contributor

Hi @pvanderlinden,
The documentation says "Contents of the JSON file used to describe your account credentials". If you were specifying this in a Terraform config, you'd use credentials = "${file("credentials.json")}". However, if you want to use the environment variables, you actually have to read the JSON containing the service account credentials into the environment variable itself.

Example:

export GOOGLE_CREDENTIALS=`cat credentials.json`

That being said, in my experience, the easiest way to handle these credentials if you already have the gcloud SDK installed is to login with gcloud auth login, and then have credentials = "" in your google provider. Terraform will use the gcloud SDK credentials to make calls against Google's API.

Hopefully this answers your question!

@mitchellh
Copy link
Contributor

Thanks @cblecker

@pvanderlinden
Copy link
Author

Thanks, I have to say the variable names are confusing though.

surminus added a commit to alphagov/govuk-puppet that referenced this issue Mar 6, 2017
We thought this expected a file as the documentation [appears to suggest
this](https://www.terraform.io/docs/providers/google/index.html).

Unfortunately this isn't the case, as per:
hashicorp/terraform#8493
@ghost
Copy link

ghost commented Apr 22, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants