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

Support each.* references in blocks w/ for_each #861

Closed
7 tasks
Tracked by #495
radeksimko opened this issue Apr 7, 2022 · 1 comment · Fixed by hashicorp/hcl-lang#145
Closed
7 tasks
Tracked by #495

Support each.* references in blocks w/ for_each #861

radeksimko opened this issue Apr 7, 2022 · 1 comment · Fixed by hashicorp/hcl-lang#145
Assignees
Milestone

Comments

@radeksimko
Copy link
Member

radeksimko commented Apr 7, 2022

Background

Terraform supports each.key and each.value references within resource, data or module block and anywhere where for_each meta-argument is supported, for example

resource "azurerm_resource_group" "rg" {
  for_each = {
    a_group = "eastus"
    another_group = "westus2"
  }
  name     = each.key
  location = each.value
}

https://www.terraform.io/language/expressions/references#block-local-values
https://www.terraform.io/language/meta-arguments/for_each

We don't provide any kind of support for this type of reference and if we were to do any kind of thorough validation of them we'd probably flag them as invalid today.

Expected UX

Completion

Screenshot 2022-06-01 at 12 08 41

Screenshot 2022-06-01 at 14 36 04

Screenshot 2022-06-01 at 14 36 19

Hover

Screenshot 2022-06-01 at 14 37 28

Screenshot 2022-06-01 at 14 37 49

Semantic Highlighting

Screenshot 2022-06-01 at 14 38 26

Screenshot 2022-06-01 at 14 38 46

Proposal

@xiehan xiehan added this to the v0.30.0 milestone Oct 27, 2022
jpogran added a commit to hashicorp/hcl-lang that referenced this issue Oct 28, 2022
This provides completion hints inside blocks for `for_each` and `each.*` references within `resource`, `data` and `module` blocks anywhere the `for_each` meta-argument is supported. It detects if `for_each` is used already and does not suggest duplicates and detects when it is necessary to provide `each.*` completions. This does not complete the values for `each.key` and `each.value`, e.g. `each.value.something`.

This also provides hover support for `for_each` and `each.*` references using the documentation as source.

This also provides semantic token support for `for_each` and `each.*` references.

Closes hashicorp/terraform-ls#861
jpogran added a commit to hashicorp/hcl-lang that referenced this issue Oct 28, 2022
This provides completion hints inside blocks for `for_each` and `each.*` references within `resource`, `data` and `module` blocks anywhere the `for_each` meta-argument is supported. It detects if `for_each` is used already and does not suggest duplicates and detects when it is necessary to provide `each.*` completions. This does not complete the values for `each.key` and `each.value`, e.g. `each.value.something`.

This also provides hover support for `for_each` and `each.*` references using the documentation as source.

This also provides semantic token support for `for_each` and `each.*` references.

Closes hashicorp/terraform-ls#861
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants