variable "host" {
type = string
}
variable "user" {
type = string
}
When I currently view this declaration in VS Code, it will indicate the references through a CodeLens:
Now when I refactor this code into a single object instead:
variable "connection" {
type = object({
host = string
user = string
})
}
Now when I change my code to use var.connection.host and var.connection.user, no CodeLens appears. The “Go to References” feature also no longer works.
Hi @oliversalzburg
This looks like a bug or missing feature to me.
I was able to reproduce it using the following snippet:
variable "connection" {
type = object({
host = string
user = string
})
}
output "name" {
value = var.connection.host
}
Not only I would expect the reference count code lens to be present, but also completion to provide host and user after var.connection., which also doesn’t seem to be happening.
Also looks like using certain default values you lose the reference. So far I have noticed true, false, and null cause the reference to be removed. Although after further playing this seems sporadic. Sometimes it works and sometimes it doesn’t.
In this case it works:
variable "root_volume_ebs_optimized" {
description = "If true, the launched EC2 instance will be EBS-optimized."
default = false
}
In this case it doesn’t:
variable "enable_auto_unseal" {
description = "Enable auto unseal of the Vault cluster"
default = false
}
@mmowatt The references currently strictly rely on types of values or variables, and so if the place where you are referencing either one of your “bool” variables doesn’t explicitly accept “bool” then it currently won’t be recognized as a reference by the language server.
We generally recommend types to be aligned whenever possible, even if some types are automatically converted. It makes the resulting config easier to read and follow for everyone.