Hi I'm using the new "resource for_each" construct introduced in Terraform 0.12 that is documented here:
https://www.terraform.io/docs/configuration/resources.html#for_each-multiple-resource-instances-defined-by-a-map-or-set-of-strings
"Terraform validate" reports no errors, however the mauve.terraform extension reports a schema error exposed through the "peek problem" UI.
Here is the associated configuration syntax, which is valid:
resource "azurerm_subnet" "vnet_hub_subnets" {
for_each = var.subnets
name = each.key
resource_group_name = azurerm_resource_group.resource_group_01.name
virtual_network_name = azurerm_virtual_network.vnet_hub.name
address_prefix = each.value
}
Here is the peek problem reported by the extension, which is not valid:
There is no variable named "each". Did you mean "path"?Terraform Schema
VSCode version info:
Version: 1.40.0 (user setup)
Commit: 86405ea23e3937316009fc27c9361deee66ffbf5
Date: 2019-11-06T17:02:13.381Z
Electron: 6.1.2
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18363
VSCode settings:
{
"azure.resourceFilter": [
"72f988bf-86f1-41af-91ab-2d7cd011db47/f6d69ee2-34d5-4ca8-a143-7a2fc1aeca55"
],
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",
"window.zoomLevel": 1,
"team.showWelcomeMessage": false,
"git.autofetch": true,
"git.enableSmartCommit": true,
"editor.renderControlCharacters": false,
"files.eol": "\n",
"terraform.indexing": {
"enabled": false,
"liveIndexing": false,
"delay": 500,
"exclude": [
".terraform/**/*",
"**/.terraform/**/*"
]
},
"terraform.languageServer": {
"enabled": true,
"args": []
},
"[terraform]": {
}
}
mauve.terraform extension information:
Name: Terraform
Id: mauve.terraform
Description: Syntax highlighting, linting, formatting, and validation for Hashicorp's Terraform
Version: 1.4.0
Publisher: Mikael Olenfalk
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=mauve.terraform
Thanks!
I can confirm I have the same issue, latest LS and plugin installed and running with tflint also.
related to this apparently? https://github.com/juliosueiras/terraform-lsp/issues/29
Hey @endzyme, this issue as presented by @doherty100 happens in vscode.
terraform-lsp seems to be deprecated for vscode (https://github.com/juliosueiras/terraform-lsp/blob/master/docs/editors/vscode.md).
Since the two projects are a bit different, is there a way to just ignore the _each_ tag in vscode-terraform?
@filipemcg - I think the bullet point in https://github.com/juliosueiras/terraform-lsp/blob/master/docs/editors/vscode.md is confusing. It is stating that https://github.com/juliosueiras/vscode-languageclient-terraform is deprecated (not Terraform-lsp).
If you follow the link on that first bullet, it states the repo is deprecated and links to the ticket where mauve/vs-code-terraform v1.4.0 should support language servers (which is loaded as terraform-lsp).
I linked the issue because the new standard for Terraform 0.12 support is to use language servers, so this error is actually bubbled up from terraform-lsp, which is loaded by vscode-terraform.
Hey @endzyme, looking at the vscode directory for the mauve.terraform extension on my system, there is no _diags.go_ file nor _tfstructs_ directory in there, which is the place where you have added the new variables to bypass this issue (juliosueiras/terraform-lsp#29).
So I'm a bit confused how juliosueiras/terraform-lsp#29 can fix this.
I'm no vscode expert by any means, so I might be missing something.
The easy thing to do is to configure vscode-terraform in a way that it ignores certain word occurrences.
Below is the vscode settings for vscode-terraform. Is it possible to configure it in a way that it ignores the tag _each_?
"terraform.indexing": {
"enabled": true,
"liveIndexing": false,
"delay": 500,
"exclude": [
".terraform/**/*",
"**/.terraform/**/*"
]
},
"terraform.languageServer": {
"enabled": true,
"args": []
},
"[terraform]": {},
Is it possible to configure it in a way that it ignores the tag each?
To be a bit more specific, it should ignore the following:
count.index
each.key
each.value
Or, consider the above as implicit number or string variables when the resource tags contain the attribute count or for_each.
A bit more digging gets me to the following conclusions...
This PR, https://github.com/juliosueiras/terraform-lsp/pull/43, added count and each as potential dynamic variables when in a resource block, but this does not check for the presence of count or for_each. I think this is OK, because count and for_each are reserved attributes in the language (per terraform.io blog), so you can't/shouldn't use them in any other way.
Despite the PR on Dec. 19, 2019, we are still seeing this today, because the latest release of the server:
https://github.com/juliosueiras/terraform-lsp/releases
Is still at 0.0.9, which is dated Sept 18, 2019.
If I tracked all these correctly, we should expect the fix in the next language server release.
@NickDrouin those were my findings too.
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.
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.
Most helpful comment
I can confirm I have the same issue, latest LS and plugin installed and running with tflint also.