References are no longer detected when using complex types

Consider a module with 2 inputs:

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:
image

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.

Is this a bug? Is my syntax off? Something else?

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.

I have just created https://github.com/hashicorp/terraform-ls/issues/653 to track this.

1 Like

Thanks a lot. I’ll follow that ticket.