intellij-hcl icon indicating copy to clipboard operation
intellij-hcl copied to clipboard

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

Open lxop opened this issue 3 years ago • 0 comments

Prerequisites

  • [x] Ensure you have latest version of plugin installed
  • [x] Search for possible issue duplicates Maybe #281?

Installation details

  • [x] IDE version (Help->About->Copy to Clipboard) PyCharm 2020.3.4 (Community Edition) Build #PC-203.7717.65, built on March 17, 2021 Runtime version: 11.0.10+8-b1145.96 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 5.8.0-48-generic GC: ParNew, ConcurrentMarkSweep Memory: 2966M Cores: 4 Non-Bundled Plugins: org.intellij.plugins.hcl, Docker, org.toml.lang Current Desktop: ubuntu:GNOME

  • [x] intellij-hcl plugin version (Settings->Plugins) 0.7.10

  • [x] Terraform version (terraform -v)

Terraform v0.14.8
+ provider registry.terraform.io/hashicorp/archive v2.1.0
+ provider registry.terraform.io/hashicorp/aws v3.33.0

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

lxop avatar Mar 25 '21 23:03 lxop