Skip to content

Allow configuring GCP service account via provider configuration #147

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

Open
toadjaune opened this issue Oct 18, 2021 · 2 comments · May be fixed by #531
Open

Allow configuring GCP service account via provider configuration #147

toadjaune opened this issue Oct 18, 2021 · 2 comments · May be fixed by #531

Comments

@toadjaune
Copy link
Contributor

toadjaune commented Oct 18, 2021

Terraform Version

Should not be relevant, but here :

$ terraform --version
Terraform v1.0.9
on linux_amd64

The provider is v1.14.0

Affected Resource(s)

This issue affects the provider configuration itself, when connecting to GCP.
You may therefore consider it affects all resources.

Terraform Configuration Files

provider "postgresql" {
  scheme    = "gcppostgres"
  host      = "aaaaa:bbbbb:ccccc"
  username  = "user"
  port      = 5432
  password  = "password123"
  superuser = false
}

The values above are placeholders, but should not matter here.

Debug Output

N/A

Panic Output

N/A

Desired Behavior

I'd like a config option to provide the service account credentials directly to the provider, for example something like :

provider "postgresql" {
  scheme    = "gcppostgres"
  host      = "aaaaa:bbbbb:ccccc"
  username  = "user"
  port      = 5432
  password  = "password123"
  superuser = false

  gcp_credentials = "/some/path/to/key.json"
}

Actual Behavior

As per the docs, such an option does not exist.

Steps to Reproduce

N/A

References

N/A

Important Factoids

Both the terraform GCP state backend and the terraform GCP provider support 2 ways to provide service account credentials :

  • explicit configuration in the provider block
  • automatic credential detection by the GCP SDK, including :
    • GOOGLE_APPLICATION_CREDENTIALS envvar
    • creds configured with gcloud auth application-default
    • Default creds configured by GCP (for example, when running on a GCP VM...)

This means that using this provider together with the official GCP provider/backend creates an API inconsistency regarding authentication, which has several implications :

  • When using multiple service accounts across multiple configurations, users need to manually reimplement logic to pass the correct service account when invoking terraform. With the GCP provider, it would be possible to manage this case only with terraform provider configuration
  • It's not possible to use the provider with a service account created by terraform in the same run. It would be with such an API.

If such an option is implemented, I'd suggest making sure it does have the same behavior as the official provider. In particular, credentials field in the official provider can either be configured with a string containing a json key, or a path to a file containing such a key.

I assume the Gocloud library accepts such a parameter, and that the logic to implement in this provider would be minimal. Mostly, accepting an extra optional argument, then, if present, validating its structure and passing it to gocloud.
I tried looking into gocloud to see if this was possible, but I'm no go dev, and got lost pretty fast.

@freick
Copy link

freick commented Nov 15, 2021

Good point. I would also like to see this implemented. 😃

@darthr4v3m
Copy link

We're a working to add this argument here, feel free to contribute.

As soon as we're ready I think we'll do a PR.

r4b6i0 added a commit to r4b6i0/terraform-provider-postgresql that referenced this issue Mar 31, 2025
The argument can be used to configure the provider with google credentials. This is an alternative to setting the GOOGLE_APPLICATION_CREDENTIALS environment variable
r4b6i0 added a commit to r4b6i0/terraform-provider-postgresql that referenced this issue Mar 31, 2025
The argument can be used to configure the provider with google credentials. This is an alternative to setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable
@r4b6i0 r4b6i0 linked a pull request Mar 31, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants