Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show interpolated expression values on hover #495

Open
4 of 7 tasks
radeksimko opened this issue May 7, 2021 · 0 comments
Open
4 of 7 tasks

Show interpolated expression values on hover #495

radeksimko opened this issue May 7, 2021 · 0 comments

Comments

@radeksimko
Copy link
Member

radeksimko commented May 7, 2021

Use-cases

Terraform supports a number of expressions (such as function calls, arithmetic operators, references etc.).

While expressions help users achieve and increase readability of their configurations they can make it harder to tell what exact value a complex expression will interpolate into, until plan phase.

For example

resource "aws_vpc" "example" {
  count      = 3
  cidr_block = "10.0.${count.index}.0/24"
}

locals {
  number_of_subnets = length(aws_vpc.example) * 3
}

when hovering over number_of_subnets we could display

number_of_subnets number
length(aws_vpc.example) * 3 = 9

in the hover popup and when hovering over cidr_block we could try to enumerate over the first few indexes and display e.g.

cidr_block string

10.0.0.0/24 (count.index = 0)
10.0.1.0/24 (count.index = 1)
10.0.2.0/24 (count.index = 2)

Proposal

hcl-lang

terraform-ls

  • Update hcl-lang

Considerations for MVP

Initially we can consider just interpolation with context from within the configuration.

Later we can consider adding external sources, such as variables and state as reflecting these is likely going to involve more effort.

Blockers (upstream)

This is currently blocked as reimplementing whole interpolation logic within LS has quite high cost of maintenance cost and TF Core does not provide any way of doing interpolation on demand.

The best way would likely be some form of gRPC interface where TF Core acts as a gRPC server which LS can start on initialize and send arbitrary expressions for Core to evaluate and return back the result as gRPC response which can be reconstructed back into cty.Value on LS side. Such an interface doesn't exist yet and has not been RFC'd or planned in any level of detail yet.

@radeksimko radeksimko added enhancement New feature or request textDocument/hover labels May 7, 2021
@xiehan xiehan added this to the v0.32.0 milestone Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants