vscode-terraform
vscode-terraform copied to clipboard
"no declaration found" for heteregeneous list
Extension Version
v2.29.5
VS Code Version
Version: 1.87.2 (Universal) Commit: 863d2581ecda6849923a2118d93a088b0745d9d6 Date: 2024-03-08T15:21:31.043Z Electron: 27.3.2 ElectronBuildId: 26836302 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Darwin arm64 23.3.0
Operating System
macOS 14.3 (23D56)
Terraform Version
1.7.5
Steps to Reproduce
a = [
{
foo = "bar"
x = [1]
},
{
foo = "baz"
}
]
b = [for e in local.a : e]
}
Expected Behavior
No errors.
Actual Behavior
local.a is marked as an error showing No declaration found.
Terraform Configuration
locals {
a = [
{
foo = "bar"
x = [1]
},
{
foo = "baz"
}
]
b = [for e in local.a : e]
}
Project Structure
No response
Gist
No response
Anything Else?
Seems similar to #1698 and disabling "terraform.validation.enableEnhancedValidation" gets rid of the problem.
Either removing local.a[0]["x"] or adding a `local.a[1]["x"] so that the objects are homogeneous in format also gets rid of the error.
Workarounds
No response
References
No response
Help Wanted
- [ ] I'm interested in contributing a fix myself
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
I seem to be having this problem within lookups and joins where the input var is local and is either a list or a map on 2.29.5 also. The variable in question is also interpolated in a string.
We encounter the same issue. In our case, the code is mapping an object to another and filling defaults - the missing records are a feature we need to reduce verbosity.
locals {
a = [
{
foo = "bar"
x = [1]
},
{
foo = "baz"
}
]
b = [for e in local.a : { foo: e.foo , x = try(e.x, [2]) } ]
}
Have the same issue for months ...
I observe the same issue at version 2.34.0.
Apparently it happens on locals which value is defined with an expression surrounded by [], like a list literal or for expression used with [].
Workaround
Using the concat funtion to avoid top level [] removes the error for me.
not_found_declaraion_elsewhere = [
for i, letter in ["f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"] :
"/dev/sd${letter}"
]
fixed = concat([
for i, letter in ["f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"] :
"/dev/sd${letter}"
])
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 details necessary to investigate further.