petoju / terraform-provider-mysql

Terraform MySQL provider – unofficial fork
https://registry.terraform.io/providers/petoju/mysql
Mozilla Public License 2.0
63 stars 40 forks source link

GCP auth and Terraform Cloud #73

Open azhurbilo opened 1 year ago

azhurbilo commented 1 year ago

Thnx for your provider, locally it works great for Google Cloud SQL instances using IAM auth 👍

locally it works because it uses https://cloud.google.com/docs/authentication/application-default-credentials#personal

but in Terraform Cloud it's not possible to pass files as credentials, only environment variables

problem that GOOGLE_APPLICATION_CREDENTIALS requires path to file (not a content of file)

You can use the GOOGLE_APPLICATION_CREDENTIALS environment variable to provide the location of a credential JSON file.

GOOGLE_CREDENTIALS env vars is possible to set in Terraform cloud but this provider doesn't handle it

Maybe you have idea how we can pass credentials as ENV var to this provider (not credentials as file)?

Terraform Version

1.3.6

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

provider "mysql" {
  endpoint = "cloudsql://***"
  username = "***"
  password = "***"
}

Expected Behavior

Ability to use "mysql" provider in Terraform Cloud

Actual Behavior

Error: failed to register driver failed to create token source: google: error getting credentials using GOOGLE_APPLICATION_CREDENTIALS environment variable: open *****: no such file or directory

Steps to Reproduce

Use "mysql" provider in environment where it's not possible to use files, only environment variables

petoju commented 1 year ago

This is technically possible by providing some defaults to cloudsql.RegisterDriver when they are given (possibly by environment variables or provider configuration).

Would you write a pull request? That would work for me.