VladRassokhin / intellij-hcl

HCL language support for IntelliJ platform based IDEs
Apache License 2.0
244 stars 47 forks source link

Interpolation of item attribute in for expression marked as error "Unknown resource type" #329

Open lxop opened 3 years ago

lxop commented 3 years ago

Prerequisites

Installation details

Terraform Configuration Files

locals {
  object_items = [
    {
      a = "1"
      b = "2"
    },
    {
      a = "3"
      b = "4"
    }
  ]
  as_map = {
    for item in local.object_items : "key-${item.a}" => "value-${item.b}"  # <-- errors here
  }
  as_list = [
    for item in local.object_items : "just-${item.a}"  # <-- error here
  ]

  list_items = [["a"], ["b"], ["c"]]
  as_list2 = [
    for item in local.list_items : "text-${item[0]}"  # <-- error here
  ]
}

Expected Behavior

All of this code should be accepted as valid (Terraform itself is happy with it)

Actual Behavior

The interpolations in the strings are marked as errors, specifically Unknown resource type on the item tokens and Unresolved reference a/b on the a/b attributes.

When these attributes (or indices) are accessed directly (without being in a string interpolation), no errors are shown, it all works fine.

Steps to Reproduce

  1. Paste the above snippet into a .tf file (not a scratch file - for some reason the errors are not reported there)
  2. Observe the errors