hashicorp / vscode-terraform

HashiCorp Terraform VSCode extension
https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform
Mozilla Public License 2.0
926 stars 179 forks source link

Recognise local references in dynamic blocks #1870

Open anthonyma94 opened 1 week ago

anthonyma94 commented 1 week ago

Extension Version

v2.33.0

VS Code Version

Version: 1.94.2 (system setup) Commit: 384ff7382de624fb94dbaf6da11977bba1ecd427 Date: 2024-10-09T16:08:44.566Z Electron: 30.5.1 ElectronBuildId: 10262041 Chromium: 124.0.6367.243 Node.js: 20.16.0 V8: 12.4.254.20-electron.0 OS: Windows_NT x64 10.0.19045

Operating System

WSL Ubuntu 24.04

Terraform Version

Terraform 1.8.4

Steps to Reproduce

locals {
  user_attributes = {
    email = {
      name                = "email"
      attribute_data_type = "String"
    }
    "selected_tenant" = {
      name                     = "custom:selected_tenant"
      attribute_data_type      = "String"
      developer_only_attribute = false
      mutable                  = true
      string_attribute_constraints = {
        max_length = 2048
        min_length = 0
      }
    }
  }
}

resource "aws_cognito_user_pool" "name" {
 ...
  dynamic "schema" {
    for_each = { for k, s in local.user_attributes : k => s }
    # no syntax highlighting or intellisense for schema
    #####################################################################
    content {
      attribute_data_type      = schema.value.attribute_data_type
      name                     = replace(schema.value.name, "custom:", "")
      developer_only_attribute = lookup(schema.value, "developer_only_attribute", null)
      mutable                  = lookup(schema.value, "mutable", null)
    }
  }
}

Expected Behavior

Not sure if it's supported, but having syntax highlighting and intellisense would be nice.

Actual Behavior

No syntax hightlighting or intellisense.

Terraform Configuration

No response

Project Structure

No response

Gist

No response

Anything Else?

No response

Workarounds

No response

References

No response

Help Wanted

Community Note

dbanck commented 1 week ago

Hi @anthonyma94,

Thanks for the report. You're right, we don't currently recognise "local" references within the dynamic block, such as schema.* in your example. This affects completion, hover, go-to-* and semantic token highlighting.

What makes these local references different from other local references we already support (such as count.index, each.*, and self.*) is that apart from the first segment, such as schema above, the rest of the address is entirely dependent on interpolating the supplied expression/variable inside for_each.

I'll rename this as a feature request if you don't mind.