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 "local" when "local" is used as a variable in a for loop #1690

Open
1 task
mymasse opened this issue Apr 23, 2024 · 2 comments
Open
1 task
Labels
bug Something isn't working

Comments

@mymasse
Copy link

mymasse commented Apr 23, 2024

Language Server Version

v0.33.0

Terraform Version

Terraform v1.8.0 on linux_amd64

Client Version

VSCode 1.87.0

Terraform Configuration

locals {
  repos = {
    local = {
      "repo1" = {
        description = "repo1"
      }
    }
    remote = {
      "repo2" = {
        description = "repo2"
      }
    }
    virtual = {
      "repo3" = {
        description = "repo3"
      }
    }
  }
}

resource "artifactory_virtual_debian_repository" "this" {
  for_each = local.repos.virtual

  key         = each.key
  description = each.value.description

  repositories = [
    concat(
      [for local in artifactory_local_debian_repository.local: local.key],
      [for remote in artifactory_local_debian_repository.remote: remote.key]
    )
  ]
}

Steps to Reproduce

  1. Open VSCode
  2. Create a main.tf with the above content

Expected Behavior

No warning are displayed (none did in version prior to 0.33.0). Terraform applies this configuration as expected with no errors.

Actual Behavior

Problem listed for the following line:

Line: [for local in artifactory_local_debian_repository.local: local.key],
Error: No declaration found for "local.key"

Gist

No response

Workarounds

Changing [for local in artifactory_local_debian_repository.local: local.key], to [for local_repo in artifactory_local_debian_repository.local: local_repo.key], removes the problem.

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
@mymasse mymasse added the bug Something isn't working label Apr 23, 2024
@mymasse
Copy link
Author

mymasse commented Apr 23, 2024

Updated to language server 0.33.1 and the problem persists

@dbanck
Copy link
Member

dbanck commented Apr 26, 2024

Thanks for report @mymasse! I'm able to reproduce the bug.

The language server currently assumes that local.key refers to a local variable of that name, which is wrong in the context of this for loop.

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

No branches or pull requests

2 participants