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

Unable to retrieve schemas - Backend authentication failure #142

Closed
tonyghita opened this issue Jun 5, 2020 · 8 comments
Closed

Unable to retrieve schemas - Backend authentication failure #142

tonyghita opened this issue Jun 5, 2020 · 8 comments
Labels
bug Something isn't working upstream/tf-core

Comments

@tonyghita
Copy link

Hi team! I'm super excited about the v2.0.0 release, so I went ahead and installed v2.0.0.rc.1.

I noticed that the terraform-ls language server exits with status code 1 in my project.

2020/06/05 07:15:26 schema_storage.go:116: error obtaining schemas: Unable to retrieve schemas: failed to get schemas: terraform (pid 93743) exited (code 1): exit status 1
stdout: ""
stderr: "\x1b[31m\n\x1b[1m\x1b[31mError: \x1b[0m\x1b[0m\x1b[1mNo valid credential sources found for AWS Provider.\n\tPlease see https://terraform.io/docs/providers/aws/index.html for more information on\n\tproviding credentials for the AWS Provider\x1b[0m\n\n\x1b[0m\x1b[0m\x1b[0m\n"

My terraform remote state is kept in AWS S3, and typically I use the AWS_PROFILE environment variable to specify which set of credentials to use.

For convenience, I've setup and .envrc file that automatically sets the correct AWS_PROFILE value based on the directory I'm in.

I think the issue is that the language server has no idea about AWS_PROFILE. I'm wondering whether:

  1. there is some configuration that can be provided to terraform-ls via vscode-terraform to pass the correct AWS credential source
  2. the configuration can be set per working directory

Thanks for reading this!

@aeschright aeschright transferred this issue from hashicorp/vscode-terraform Jun 5, 2020
@radeksimko
Copy link
Member

Hi @tonyghita
Can you try upgrading to the latest LS v0.3.2? (the VSCode extension should show popup with an upgrade on launch/restart) It contains a change which allows the LS to pass through all environment variables.

FWIW though we are still working out what the ideal UX be around these cases. The tricky thing is getting VSCode (or any GUI app really) to read the appropriate environment variable and then once you do that you need to realize that it will propagate those variables down to all instances of the LS which may be instances serving many different workspaces/folders. Therefore it's actually desirable for the LS to somehow re-read any workspace/folder-specific variables, which it doesn't do currently.

I can see you are already aware of this challenge if you use .envrc - so this is useful feedback for us as we can consider supporting direnv in LS and prompt re-reading the relevant variables when switching between folders in VSCode.

In the meantime there is a few workarounds:

  • remember to reopen VSCode with the correct variables when switching between folders
  • utilize -tf-exec flag and repoint it to a wrapper shell script which would essentially re-read the right variables and execute terraform with those

@tonyghita
Copy link
Author

Hey @radeksimko, thanks for the speedy response.

I've tried installing the latest language server via VS Code, but I no longer see the option for terraform-ls in the Output tab so I'm not quite sure where it is. I'm also not sure where to see if the language server is enabled or disabled. 🤔

The wrapper script is an interesting idea—I'll look into the -tf-exec flag.

Is there any documentation available for which configuration settings are possible for terraform-ls within VS Code? What would be the best way to discover those.

@tonyghita
Copy link
Author

tonyghita commented Jun 6, 2020

I was able to install 0.3.2, but ran into an issue I don't understand as soon as the language server starts.

Launching language server: /Users/tonyghita/.vscode/extensions/hashicorp.terraform-2.0.0-rc.1/lsp/terraform-ls serve
[Error - 3:33:55 PM] Connection to server is erroring. Shutting down server.
[Error - 3:33:55 PM] Connection to server is erroring. Shutting down server.
[Error - 3:33:55 PM] Connection to server is erroring. Shutting down server.
[Error - 3:33:55 PM] Connection to server is erroring. Shutting down server.

@radeksimko
Copy link
Member

radeksimko commented Jun 7, 2020

@tonyghita Assuming you're on macOS Catalina, then I believe this is a bug I described in hashicorp/vscode-terraform#341 which Audrey fixed recently in hashicorp/vscode-terraform#343 (released as part of rc.2).

Can you try installing the latest rc from here? https://github.com/hashicorp/vscode-terraform/releases

Is there any documentation available for which configuration settings are possible for terraform-ls within VS Code? What would be the best way to discover those.

The best way to discover these for now would be executing terraform-ls serve --help, but I understand that you may not have the LS in your $PATH - so you'd need to cd into /Users/tonyghita/.vscode/extensions/hashicorp.terraform-2.0.0-rc.1/lsp/ in your case first.
Discovering all options is not ideal when the LS is installed via VSCode, but we can address that with some more accessible docs published on the Terraform website and/or elsewhere in the future.

@tonyghita
Copy link
Author

I'm on macOS Mojave—the terraform-ls "sudden death" issue in VS Code is fixed in the v2.0.0-rc.2 release for me.

Thank you for the helpful responses 👍

@paultyng paultyng changed the title terraform-ls: failed to get schemas from AWS S3 remote Unable to retrieve schemas - Backend authentication failure Jun 11, 2020
@paultyng paultyng added bug Something isn't working upstream/tf-core labels Jun 11, 2020
@paultyng
Copy link
Contributor

I posted this in a related issue, but just for anyone viewing, a workaround to explicitly set environment for Terraform can be achieved by writing a custom script to run Terraform with those env vars and passing it as the Terraform executable: https://github.com/hashicorp/vscode-terraform/wiki/Manually-Setting-the-Terraform-Executable-Path

That being said, backend authentication should NOT be required for schema, so we are going to see how we can solve this within the LS.

@paultyng
Copy link
Contributor

Going to merge this with #128 to consolidate backend authentication issues.

@ghost
Copy link

ghost commented Jul 18, 2020

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 context necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jul 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working upstream/tf-core
Projects
None yet
Development

No branches or pull requests

3 participants