Skip to content

import using for_each flagged as Unexpected attribute #2097

@bahag-klickst

Description

@bahag-klickst

Extension Version

v2.35.0

VS Code Version

Version: 1.103.2 (Universal)
Commit: 6f17636121051a53c88d3e605c491d22af2ba755
Date: 2025-08-20T16:45:34.255Z (1 wk ago)
Electron: 37.2.3
ElectronBuildId: 12035395
Chromium: 138.0.7204.100
Node.js: 22.17.0
V8: 13.8.500258-electron.0
OS: Darwin arm64 24.5.0

Operating System

macOS Sequoia 15.5

Terraform Version

Terraform v1.13.1

Steps to Reproduce

Create an import resource using for_each

Expected Behavior

import is recognized to accept for_each

Actual Behavior

Code is seen as wrong with the error message
Unexpected attribute: An attribute named "for_each" is not expected here

Terraform Configuration

variable "cloud_sql_import_ids" {
  type = list(object({
    name = string
    id   = string
  }))
  default     = []
  description = "A list of objects to import for cloud sql"
}

import {
  for_each = length(var.cloud_sql_import_ids) > 0 ? { for k, v in var.cloud_sql_import_ids : v.name => v } : {}
  to       = google_sql_database_instance.master[each.key]
  id       = each.value.id
}

Project Structure

Gist

No response

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions