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

[Feature Request] Support for terraform login credentials #146

Closed
sean-nixon opened this issue Mar 17, 2020 · 8 comments
Closed

[Feature Request] Support for terraform login credentials #146

sean-nixon opened this issue Mar 17, 2020 · 8 comments

Comments

@sean-nixon
Copy link

Terraform 0.12.21 added a terraform login command which populates credentials at $HOME/.terraform.d/credentials.tfrc.json (not sure if the Windows Path differs). It would be great if the TFE provider could pick up those credentials automatically in addition to the currently supported methods of the TFE_TOKEN environment variable and the CLI config file.

@straubt1
Copy link

straubt1 commented Apr 3, 2020

This would be great!

@tristanmorgan
Copy link
Member

Is this related to #111 in how credentials are retrieved?

@sean-nixon
Copy link
Author

@tristanmorgan I think credentials_helper is separate from the terraform login functionality and credential storage

@tristanmorgan
Copy link
Member

My poorly worded comment was more about how the TFE provider should use the same code for storage and retrieval of tokens as the login in terraform cli. similar to this issue in the provider for Vault.

@sean-nixon
Copy link
Author

Gotcha. I don’t disagree with you there.

@bendrucker
Copy link
Contributor

Hey guys, they are related and have the same solution. terraform login (and logout) does call a credential helper if you have one defined. Shameless plug for a credential helper you might want to try 😄:

https://github.com/bendrucker/terraform-credentials-keychain

Here's an example of using the cliconfig package to load the configuration and get credentials for a given host:

https://github.com/bendrucker/terraform-cloud-cli/blob/master/cmd/meta.go#L30-L72

That ends up invoking the credential helper as long as you don't have statically defined token for that host.

Terraform is versioned as a CLI and not a library, so there are no versioning guarantees around those packages. There may be some hesitation from the maintainers around re-introducing that coupling now that terraform-plugin-sdk is a thing. If a Terraform version made breaking changes, the provider can't readily switch on TerraformVersion and call different versions of the libraries, since the two versions will have the same major identifier.

I don't have a pressing personal need for this feature but I'm happy to provide feedback on a PR.

@rorychatterton
Copy link

This provider already supports .terraformrc - it should be trivial to upgrade it to support the $HOME/.terraform.d/credentials.tfrc.json file.

The file parsing logic is here:
https://github.com/terraform-providers/terraform-provider-tfe/blob/7995bdae588a5758da9ecf422284b2c919010ea4/tfe/provider.go#L212

This would just need to be split into two file provider types, one that parses HCL, one JSON.

The lookup logic is in these two files:
Nix: https://github.com/terraform-providers/terraform-provider-tfe/blob/master/tfe/config_unix.go
Windows: https://github.com/terraform-providers/terraform-provider-tfe/blob/master/tfe/config_windows.go

I'd suggest we want to set the order of residence as credentials.tfrc.json BEFORE .terraformrc

Then finally just update the docs with the new lookup.

I won't get a chance to look at this in the next week, but seems relatively easy for somebody else to pickup. In the interim, I'd suggest tracking the credential helper convo in the other thread linked #111

@grantorchard
Copy link

After a quick look at that code I thought it worth trying this as a workaround, and it seems to be working working with the TFE provider after a couple of different tests.

export TERRAFORM_CONFIG=/Users/grant/.terraform.d/credentials.tfrc.json

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

No branches or pull requests

7 participants