hashicorp / hashicorp/vscode-terraform
Can't specify environment variables for terraform executable
- Dominant language
- TypeScript
- Stars
- 975
- Forks
- 196
- Avg merge
- 2h 47m
- Merged PRs (30d)
- 1
Description
Since the last update, every time I open a Terraform file in VS Code, I get an error message:
```
No schema found for "tf". Functionality may be limited. You may need to run terraform init.
```
(`tf` is a directory containing my root Terraform module.)
Running `terraform init` does not help.
----
I've tracked the error to this message:
```
2021/02/18 14:58:30 module_ops.go:114: failed to obtain schema:
Error: Error loading state: AccessDenied: Access Denied
status code: 403, request id: 0Q5P3SFX6G2M1VEY, host id: 6/I8BD9TL/UuTqoXjOK5UOJqHn1bm6HHcqa3Mtjwv8EId7p5e5Zf7tIcP8SM/KpYfIk27lejnvg=
```
Indeed, my remote state is on AWS S3 and my `default` AWS account does not have access to the Terraform state bucket.
----
I handle a number of AWS accounts, and I've taken the habit to call the AWS CLI with `--profile` to specify which profile I'm using. Or, in most cases, I `export` `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` in my shell, and Terraform picks it up from there.
How can I tell `terraform-vscode` to use the correct AWS credentials? Perhaps an added argument to `terraform.languageServer` could help? E.g.
```json
"terraform.languageServer": {
"external": true,
"args": [
"serve"
],
"env": {
"AWS_ACCESS_KEY_ID": "AKIAAAAAAAAAAAAAAAAA",
"AWS_SECRET_ACCESS_KEY": "kfPY2ir/99y9bPf5ykpZ+kPKaYabkBUaZeUk7zKo"
}
```
Contributor guide
Research direction
Start with the terraform.languageServer configuration shown in the issue and trace how its external process is launched. Confirm how environment variables could reach the Terraform language server, then verify that credentials configured there allow schema loading for a remote AWS S3 state without exposing secrets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, terraform
- Domain
- cloud, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100