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

Local variable with and empty map or list report error not declare #1576

Closed
1 task
martinOrigin8Cares opened this issue Oct 5, 2023 · 7 comments
Closed
1 task
Assignees
Labels
bug Something isn't working diagnostics

Comments

@martinOrigin8Cares
Copy link

Extension Version

GitLab.gitlab-workflow@3.80.0

VS Code Version

Version: 1.83.0 (user setup)
Commit: e7e037083ff4455cf320e344325dacb480062c3c
Date: 2023-10-03T16:12:16.321Z
Electron: 25.8.4
ElectronBuildId: 24154031
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.22631

Operating System

Edition Windows 11 Pro Version 23H2 Installed on ‎2023-‎10-‎01 OS build 22631.2361 Experience Windows Feature Experience Pack 1000.22674.1000.0

Terraform Version

Terraform v1.6.0 on linux_amd64

Steps to Reproduce

  1. Just create a file with the terraform configuration below
  2. Over the word that has the "red underlying text"
  3. You will the reporting that the variable is not declare

image

Expected Behavior

To not shwo an error

Actual Behavior

Show the error "No declaration found for <>"

Terraform Configuration

locals {
  map1 = {
    param1 = "foo"
    param2 = "bar"
  }
  map2 = {} # If the variable is an empty map, intellisense report "No declaration found"
  merge_map1 = merge(local.map1, local.map2)

  list1       = ["foo", "bar"]
  list2       = [] # If the variable is an empty map, intellisense report "No declaration found"
  concat_list1 = concat(local.list1, local.list2)

  map3 = {
    param1 = "foo"
    param2 = "bar"
  }
  map4 = map({}) # Now intellisense work
  merge_map2  = merge(local.map3, local.map4)

  list3       = ["foo", "bar"]
  list4       = list([]) # Now intellisense work
  concat_list2 = concat(local.list3, local.list4)
}

Project Structure

.
└── maint.tf

Gist

https://gist.github.com/martinOrigin8Cares/f96e3dabdcaec56620f5dd64b458a64b

Anything Else?

No response

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
@martinOrigin8Cares martinOrigin8Cares added the bug Something isn't working label Oct 5, 2023
@radeksimko
Copy link
Member

radeksimko commented Oct 6, 2023

Thank you for the report @martinOrigin8Cares, I was able to reproduce it and I can confirm this is a bug.

It can see that the two complex types do not match exactly, as the hover also indicates. For clarity, unless there's constraint given by a provider/resource/data source, then [] is assumed tuple, not list. Similarly, {} is assumed object, not map.

This is already (correctly) reflected in the hover data:

2023-10-06 07 26 00

You probably understood the difference already given that you came up with the workaround with tolist() and tomap() but I thought I'd clarify this anyway for the benefit of others.

All that said, these two pairs of types (tuple / list and map/object) are convertible in this case and so we shouldn't be raising it as a diagnostic error as terraform validate doesn't either.

I will look into tweaking the type matching logic.

@radeksimko
Copy link
Member

This actually ended up to be more related to the fact that the tuples and objects are empty, rather than their underlying types, as you originally hinted in your post.

Either way I have a patch in hashicorp/hcl-lang#330 which is now pending review.

I will post updates here when we merge it and release it (hopefully soon).

Thanks for your patience in the meantime.

@radeksimko
Copy link
Member

A new version 2.28.1 was just released. This fixes the reported bug. The update should appear automatically in VS Code.

Thank you for the detailed repro case in your report @martinOrigin8Cares


In case you experience any different validation related bug, please do let us know through a new issue.

@nagendran78
Copy link

I still see the error displayed on the VSCode despite updating the extension to version 2.28.1

@radeksimko
Copy link
Member

I still see the error displayed on the VSCode despite updating the extension to version 2.28.1

In case you experience any different validation related bug, please do let us know through a new issue and attach a repro case. Thanks.

@ghost
Copy link

ghost commented Oct 12, 2023

@radeksimko, should version 2.28.1 already fix the issue with empty tuples/lists?
I still get the "no declaration found" on a variable definded like this:

variable "public_restricted_allow" { description = "Restrict CIDR ranges allowed to access public subnets" type = list(string) }
Worked fine on versions <= 2.27.2

@radeksimko
Copy link
Member

In case you experience any different validation related bug, please do let us know through a new issue and attach a full repro case in the form of configuration.

@FeltlP In your particular case we'd also need the snippet of the configuration which has the reference since it depends on the context in which it is referenced.

Thanks.

@hashicorp hashicorp locked as resolved and limited conversation to collaborators Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working diagnostics
Projects
None yet
Development

No branches or pull requests

3 participants