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

"no declaration found" for heteregeneous list #1708

Closed
1 task
vincer opened this issue Mar 15, 2024 · 4 comments · Fixed by hashicorp/terraform-ls#1884
Closed
1 task

"no declaration found" for heteregeneous list #1708

vincer opened this issue Mar 15, 2024 · 4 comments · Fixed by hashicorp/terraform-ls#1884
Labels
bug Something isn't working

Comments

@vincer
Copy link

vincer commented Mar 15, 2024

Extension Version

v2.29.5

VS Code Version

Version: 1.87.2 (Universal)
Commit: 863d2581ecda6849923a2118d93a088b0745d9d6
Date: 2024-03-08T15:21:31.043Z
Electron: 27.3.2
ElectronBuildId: 26836302
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Darwin arm64 23.3.0

Operating System

macOS 14.3 (23D56)

Terraform Version

1.7.5

Steps to Reproduce

  a = [
    {
      foo = "bar"
      x   = [1]
    },
    {
      foo = "baz"
    }
  ]

  b = [for e in local.a : e]
}

Expected Behavior

No errors.

Actual Behavior

local.a is marked as an error showing No declaration found.

Terraform Configuration

locals {
  a = [
    {
      foo = "bar"
      x   = [1]
    },
    {
      foo = "baz"
    }
  ]

  b = [for e in local.a : e]
}

Project Structure

No response

Gist

No response

Anything Else?

Seems similar to #1698 and disabling "terraform.validation.enableEnhancedValidation" gets rid of the problem.

Either removing local.a[0]["x"] or adding a `local.a[1]["x"] so that the objects are homogeneous in format also gets rid of the error.

Workarounds

No response

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@vincer vincer added the bug Something isn't working label Mar 15, 2024
@prototype7630
Copy link

prototype7630 commented Apr 3, 2024

I seem to be having this problem within lookups and joins where the input var is local and is either a list or a map on 2.29.5 also. The variable in question is also interpolated in a string.

@eldad
Copy link

eldad commented Apr 5, 2024

We encounter the same issue. In our case, the code is mapping an object to another and filling defaults - the missing records are a feature we need to reduce verbosity.

locals {
  a = [
    {
      foo = "bar"
      x   = [1]
    },
    {
      foo = "baz"
    }
  ]

  b = [for e in local.a : { foo: e.foo , x = try(e.x, [2]) } ]
}

@hronix
Copy link

hronix commented Oct 9, 2024

Have the same issue for months ...

@jmriddell
Copy link

I observe the same issue at version 2.34.0.

Apparently it happens on locals which value is defined with an expression surrounded by [], like a list literal or for expression used with [].

Workaround

Using the concat funtion to avoid top level [] removes the error for me.

not_found_declaraion_elsewhere = [
  for i, letter in ["f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"] :
  "/dev/sd${letter}"
]

fixed = concat([
  for i, letter in ["f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"] :
  "/dev/sd${letter}"
])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants