`terraform login` with cli config set can not read config file
Terraform Version
v1.9.1
Terraform Configuration Files
credentials "app.terraform.io" {
token = "xxxxxx.atlasv1.zzzzzzzzzzzzz"
}
Debug Output
There are some problems with the CLI configuration:
Error: Error reading C:\DIR_NAME\terraform: read C:\DIR_NAME\terraform: Incorrect function.
As a result of the above problems, Terraform may not behave as intended.
Expected Behavior
Login to Terraform HCL work without any issues
Actual Behavior
There is an error message saying there are problems with CLI configuration while running any terraform command. Error message is displayed even if the TF_CLI_CONFIG_FILE is not set and default APPDATA path is used. Full error is in Debug Ouput.
Steps to Reproduce
- create an API token to access the HCP Terraform API
- set TF_CLI_CONFIG_FILE to different path than
%APPDATA% - put the token to a file
terraform.tfrc(also triedterraform.rc) incredentialsblock - run any
terraformcommand
Additional Context
No response
References
No response
Hi @MichalChotvac! Sorry for this strange behavior and thanks for reporting it.
I think I recognize "Incorrect function" as the English localization of the windows error code that means that Terraform attempted to perform a filesystem operation that doesn't make sense for the file in question.
Given that, I think an important question is what is actually at the file path indicated in the error message on your system. Is that path referring to a directory, or to a file? Is there anything already in that directory/file?
Note that TF_CLI_CONFIG_FILE is supposed to refer to a single file rather than to a directory of files. If you set it to refer to a directory then Terraform will probably try to "open" that directory as if it were a file, which could potentially cause this error. If that turns out to be the cause here then I would suggest that we fix it by explicitly checking whether the given path points to a file and return a more actionable error message if not, rather than just returning directly the error message returned by the operating system.
Hi @apparentlymart ,thank you for your response and sorry for being late in mine. You were right, I have set the variable to the directory. But meantime I have updated terraform to v1.9.2 and specified a file (*.rc) in TF_CLI_CONFIG_FILE variable, but now I am seeing other error:
PS C:\xx\xx> terraform login
╷
│ Error: Credentials for app.terraform.io are manually configured
│
│ The "terraform login" command cannot log in because credentials for this host are already configured in a CLI
│ configuration file.
│
│ To log in, first revoke the existing credentials and remove that block from the CLI configuration.
╵
Hi @MichalChotvac,
The terraform login command works by adding a new file to the default directory where Terraform searches for CLI configuration files, and so it isn't really compatible with the situation where you have overridden Terraform to use only one specific CLI configuration file.
If you want to use terraform login then you must not set TF_CLI_CONFIG_FILE. Or conversely, if you want to use TF_CLI_CONFIG_FILE then you will need to manually add the credentials "app.terraform.io" block to your overriding CLI configuration file, instead of using terraform login. (Or you can use one of the other supported methods for providing credentials for a service hostname, such as an environment variable.)
Since we have not heard back in a while I'm going to close the issue. If you have any updates regarding the issue, feel free to open a new issue with the requested information. If you have more questions, you can also use the community forum where there are more people ready to help.
Thanks!
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.