gruntwork-io / terraform-google-sql

Terraform modules for deploying Google Cloud SQL (e.g. MySQL, PostgreSQL) in GCP
https://gruntwork.io
Apache License 2.0
92 stars 103 forks source link

How do I set credentials? #48

Closed newtoniumx3 closed 3 years ago

newtoniumx3 commented 3 years ago

I'm using GCP and the only way I found to use my credentials file right now was to export environment variable.

export GOOGLE_APPLICATION_CREDENTIALS="../credentials.json"

I would previously define this within the provider like so:

provider "google" {
  project     = "test"
  region      = "us-central1-a"
  credentials = file("../secrets.json")
}

But when I add this credentials key to the provider (within main.tf) I get

Error: Attempted to load application default credentials since neither `credentials` nor `access_token` was set in the provider block.  No credentials loaded. To use your gcloud credentials, run 'gcloud auth application-default login'.  Original error: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
robmorgan commented 3 years ago

Hi @newtoniumx3 ,

The recommended approach is to set your GCP credentials using the environment variable you've specified. You can also use the provider blocks, but you'll need to make sure you set the credentials key and ensure its in the correct format for all google and google-beta provider blocks.

newtoniumx3 commented 3 years ago

Thank you!