terraform-ls: Failed to get schema due to backend authentication
I believe the language server is reading the remote state. Remote state requires authentication.
I have a more elaborate method of authenticating against AWS which is a wrapper that rotates keys and sets environment variables, etc.
https://github.com/99designs/aws-vault
It would be a good feature if we would wrap the language servers execution in this program. Maybe a “terraform-ls.command” option so we can define the full terraform-ls command to be executed. eg:
/usr/local/bin/aws-vault exec myProfile -- terraform-ls
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 11
- Comments: 36 (19 by maintainers)
Commits related to this issue
- terraform-lsをdirenv経由で実行できるようにする terraform providers schema -jsonがバックエンド認証を要求するが rootモジュールごとにAWSアカウントが異なり読み込む環境変数が違う。 https://github.com/hashicorp/terraform-ls/issues/128 terraformコマンドの実行パスは-tf-exec... — committed to minamijoyo/dotfiles by minamijoyo 4 years ago
- terraform-lsをdirenv経由で実行できるようにする terraform providers schema -jsonがバックエンド認証を要求するが rootモジュールごとにAWSアカウントが異なり読み込む環境変数が違う。 https://github.com/hashicorp/terraform-ls/issues/128 terraformコマンドの実行パスは-tf-exec... — committed to minamijoyo/dotfiles by minamijoyo 4 years ago
Generally a combination of config and state is needed to pick the providers before any
planorapplyoperation. Config may not be sufficient in cases where the user is removing resources - e.g. say you have a singleaws_instanceblock in your config and you remove that - then Terraform still has to figure out how to remove it, even though it’s not in the config anymore and therefore it probes the state which then prompts it to findawsprovider.I’m unsure what other use cases
terraform providers schema -jsonwas designed for, and so I can’t comment on potential implications of changing the default behaviour, but I do think there should be a way of obtaining schema from anyinitd providers, regardless of config or state. That would IMO help resolve most language server use cases.See https://github.com/hashicorp/terraform/issues/24261
So yes - I think that would be probably the ideal longer-term solution, but it still raises the question of 0.12 and any earlier 0.13 releases which may not have this feature - and these versions will be around for a while, so we’re hoping to find some solutions for these too, without having to backport any patches.
Thanks for the quick reply.
I’m seeing this in the logs quite soon after starting vscode:
Then while editing references to a missing schema file are displayed:
The workspace is initialised and all terraform actions work without errors on the command line.
Maybe I installed the extension incorrectly? I cloned into extensions directory and ran
npm install.Yikes, this issue is causing me and my org quite a headache. We pull in our AWS creds via vault (in a wrapper) and those paths differ between projects. This makes the solution suggested earlier not work in our use-case.
well or just not requiring authentication … its a definitely a bit silly my editor language server needing to do authenticated calls to terraform … it shouldn’t need to do that and its a potential security risk
ok I’m the right track now … but having one more issue now … the wrapper requires some manually entered credentials like keychain password and OTP code … these come as popups which is fine … the issue is that it seems like the language server is concurrently invoked a LOT of times … (I guess once per root) … is there a way to make it reduce the concurrency or something? if you launch them all at once … they all ask for password … if you launch them in serial the first one will ask for password only …
Can this schema document be downloaded separately and placed in a directory manually for use by the extension?