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

Cannot create temporary file to update credentials during opentf login #442

Closed
mermoldy opened this issue Sep 19, 2023 · 2 comments · Fixed by #512
Closed

Cannot create temporary file to update credentials during opentf login #442

mermoldy opened this issue Sep 19, 2023 · 2 comments · Fixed by #512
Labels
accepted This issue has been accepted for implementation. bug Something isn't working

Comments

@mermoldy
Copy link
Contributor

OpenTF Version

1.6.0

OpenTF Configuration Files

any configuration

Debug Output

➜ TF_LOG=trace opentf login app.terraform.io
2023-09-19T16:01:56.760+0300 [INFO] OpenTF version: 1.6.0 dev
2023-09-19T16:01:56.760+0300 [DEBUG] using github.com/hashicorp/go-tfe v1.32.0
2023-09-19T16:01:56.760+0300 [DEBUG] using github.com/hashicorp/hcl/v2 v2.17.0
2023-09-19T16:01:56.760+0300 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2023-09-19T16:01:56.760+0300 [DEBUG] using github.com/zclconf/go-cty v1.13.2
2023-09-19T16:01:56.760+0300 [INFO] Go runtime version: go1.21.1
2023-09-19T16:01:56.760+0300 [INFO] CLI args: []string{"opentf", "login", "app.terraform.io"}
2023-09-19T16:01:56.760+0300 [INFO] This build of OpenTF allows using experimental features
2023-09-19T16:01:56.761+0300 [TRACE] Stdout is a terminal of width 94
2023-09-19T16:01:56.761+0300 [TRACE] Stderr is a terminal of width 94
2023-09-19T16:01:56.761+0300 [TRACE] Stdin is a terminal
2023-09-19T16:01:56.761+0300 [DEBUG] Attempting to open CLI config file: /Users/mermoldy/.opentfrc
2023-09-19T16:01:56.761+0300 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2023-09-19T16:01:56.761+0300 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2023-09-19T16:01:56.761+0300 [DEBUG] ignoring non-existing provider search directory /Users/mermoldy/.terraform.d/plugins
2023-09-19T16:01:56.761+0300 [DEBUG] ignoring non-existing provider search directory /Users/mermoldy/Library/Application Support/io.terraform/plugins
2023-09-19T16:01:56.761+0300 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2023-09-19T16:01:56.761+0300 [INFO] CLI command args: []string{"login", "app.terraform.io"}
2023-09-19T16:01:56.762+0300 [DEBUG] Service discovery for app.terraform.io at https://app.terraform.io/.well-known/terraform.json
OpenTF will request an API token for app.terraform.io using your browser.

If login is successful, OpenTF will store the token in plain text in
the following file for use by subsequent commands:
/Users/mermoldy/.terraform.d/credentials.tfrc.json

2023-09-19T16:01:57.388+0300 [DEBUG] command: asking for input: "Do you want to proceed?"
Do you want to proceed?
Only 'yes' will be accepted to confirm.

Enter a value: yes


OpenTF must now open a web browser to the tokens page for app.terraform.io.

If a browser does not open this automatically, open the following URL to proceed:
https://app.terraform.io/app/settings/tokens?source=terraform-login


Generate a token using your browser, and copy-paste it into this prompt.

OpenTF will store the token in plain text in the following file
for use by subsequent commands:
/Users/mermoldy/.terraform.d/credentials.tfrc.json

2023-09-19T16:02:02.043+0300 [DEBUG] command: asking for input: "Token for app.terraform.io:"
Token for app.terraform.io:
Enter a value:

Retrieved token for user mermoldy


│ Error: Failed to save API token

│ The given host returned an API token, but OpenTF failed to save it: cannot create temporary
│ file to update credentials: open
│ /Users/mermoldy/.terraform.d/credentials.tfrc.json1252058916: no such file or directory.

Expected Behavior

The opentf creating the temporary file without errors.

Actual Behavior

│ Error: Failed to save API token

│ The given host returned an API token, but OpenTF failed to save it: cannot create temporary
│ file to update credentials: open
│ /Users/mermoldy/.terraform.d/credentials.tfrc.json1252058916: no such file or directory.

Steps to Reproduce

  1. remove ~/.terraform.d/
  2. run opentf login workflow

Additional Context

The problem arises when the ~/.terraform.d directory is missing.

Previously, ~/.terraform.d was created by the checkpoint service, which has been removed from OpenTF. The same behavior can be reproduced in Terraform by running it with CHECKPOINT_DISABLE=1. However, it's generally expected that a cli tool should create its own configuration directory by itself.

I can open a PR if this issue gets accepted.

References

No response

@mermoldy mermoldy added bug Something isn't working pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion. labels Sep 19, 2023
@Yantrio Yantrio added accepted This issue has been accepted for implementation. and removed pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion. labels Sep 19, 2023
@Yantrio
Copy link
Member

Yantrio commented Sep 19, 2023

This would be great to fix! Thanks for bringing this to our attention. I've approved this issue so feel free to move forward with a PR.

@mermoldy
Copy link
Contributor Author

@Yantrio just opened the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This issue has been accepted for implementation. bug Something isn't working
Projects
None yet
2 participants