Open
Description
Background
HCL may report an attribute key as invalid when it's unclear whether it's reference or literal key. For example:
variable "toot" {
default = "foot"
}
output "example" {
value = {
var.toot = "noot"
}
}
This is currently not surfaced directly by the LS as a diagnostic because HCL only produces the diagnostic when obtaining Value()
of the expression. The language server does use HCL parser but expressions are more often inspected as individual (Go) types one by one rather than evaluated to get the value. i.e. that codepath never gets executed in the context of LS.
It can be surfaced by running terraform validate
however:
╷
│ Error: Ambiguous attribute key
│
│ on test.tf line 7, in output "example":
│ 7: var.toot = "noot"
│
│ If this expression is intended to be a reference, wrap it in parentheses. If it's instead
│ intended as a literal name containing periods, wrap it in quotes to create a string
│ literal.
╵
and so it can also be surfaced by calling the experimental validate
command:
Proposal
- Report ambiguous attribute keys earlier than in
expression.Value()
hcl#648 - Surface
Ambiguous attribute key
diagnostic "on type" - e.g. by reimplementing the HCL detection inside ofhcl-lang
- Provide two possible quick fixes:
- Convert into reference (wrap in parentheses)
- Convert into literal name (wrap in quotes)