hashicorp / vscode-terraform

HashiCorp Terraform VSCode extension
https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform
Mozilla Public License 2.0
918 stars 178 forks source link

"Unknown" existing variable #246

Closed lego963 closed 4 years ago

lego963 commented 4 years ago

image image

samparnell commented 4 years ago

This is also happening for me. To be more specific about this issue, variables referenced directly seem to throw an error. Is the variable is referenced inside a string interpolation it seems to be accepted.

Fails validation:

user_name = var.user_name

Passes validation:

user_name = "${var.user_name}"
TimMensch commented 4 years ago

Running into this myself, plus 0.12 throws this:

Warning: Interpolation-only expressions are deprecated

  on main.tf line 13, in provider "aws":
  13:   region  = "${var.region}"

...so the only way vscode-terraform works ends up throwing warnings. Please fix!

thejosephstevens commented 4 years ago

So I would suggest killing this particular issue, it's effectively a duplicate of the large HCL2 thread in this same repo. If you follow the instructions here you should be able to get some basic terraform ide functionality in place without the faulty red lines. There are a handful of people who have been pitching in to try and get HCL2 working properly (which should cover the tf 0.12 changes)

TimMensch commented 4 years ago

Already followed the instructions. No good.

Basic functionality works. Still have red lines and parse errors.

jleechp-occm commented 4 years ago

Based on some testing I'd done (albeit with Emacs using the terraform-lsp, but coworker is having this exact issue in VSCode), try moving those variable definitions into the same *.tf file as the references and see if that removes the red lines. The LSP doesn't currently seem to look at other files in the same project (directory), so it doesn't realize the variable is defined.

TimMensch commented 4 years ago

The thing is, it does recognize variables when using string templates like "${var.region}". Just not when bare var.region.

But for completeness: Even if var.region is defined in the very same file, it still doesn't parse correctly.

And I have:

{
    "terraform.languageServer": {
        "enabled": true,
        "args": []
    }
}

...plus I selected v0.0.9 of the language server to install and run. Though all I see in the output window for it is:

2020/02/04 16:50:34 Server started

I'm on VS Code 1.14.1 on Windows 10. Does anyone actually see this behavior work on a Windows VS Code?

TimMensch commented 4 years ago

Update: I do see a lot of verbose logging in the Language Server Output panel. Stuff like:

2020/02/04 17:03:51 [DEBUG] checking for provider in "c:\\Users\\tim-m\\.vscode\\extensions\\mauve.terraform-1.4.0\\lspbin"
2020/02/04 17:03:51 [DEBUG] found provider "terraform-provider-alicloud_v1.70.1_x4.exe"
2020/02/04 17:03:51 [DEBUG] found provider "terraform-provider-archive_v1.3.0_x4.exe"
2020/02/04 17:03:51 [DEBUG] found provider "terraform-provider-aws_v2.46.0_x4.exe"
2020/02/04 17:03:51 [DEBUG] found provider "terraform-provider-azurerm_v1.42.0_x4.exe"
2020/02/04 17:03:51 [DEBUG] found provider "terraform-provider-external_v1.2.0_x4.exe"
...
2020-02-04T17:03:51.852-0700 [DEBUG] plugin: plugin process exited: path=c:\Users\tim-m\.vscode\extensions\mauve.terraform-1.4.0\lspbin\terraform-provider-aws_v2.46.0_x4.exe pid=35288
2020-02-04T17:03:51.852-0700 [DEBUG] plugin: plugin exited

It seems odd that the plugin keeps exiting like this, but ...?

paultyng commented 4 years ago

We just released v2.0.0-rc.1 of the extension. The main features include:

You can find additional information and specifics in the release notes and CHANGELOG.

With this release we expect that many of the prior issues and PRs are no longer relevant or have been addressed, and are therefore being closed. If you feel the action taken on an issue or PR is in error, please comment as such and we can figure out the appropriate way to address it.

We plan to add the final 2.0.0 release to the marketplace soon, but are actively seeking your feedback now on the release candidates. You can download the .vsix from the releases page and manually install it in VS Code to try it out.

ghost commented 4 years ago

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.