Skip to content

Import block expansion with for_each not working #34249

@AnandSagar06

Description

@AnandSagar06

Terraform Version

1.6.3

Terraform Configuration Files

this code is inside import.tf file

import {
  for_each = {
    "bucket1" = "bucket1"
    "bucket2" = "bucket2"
  }
  to = aws_s3_bucket.this[each.key]
  id = each.value
}

Debug Output


│ Error: Unsupported argument

│ on import-for-each.tf line 8, in import:
│ 8: for_each = {

│ An argument named "for_each" is not expected here.

Expected Behavior

I expected both the existing s3 buckets "bucket1" and "bucket2" to be imported at once into our TF workspace.

Actual Behavior

It resulted in an error saying "An argument named "for_each" is not expected here".
But I see this feature to support for_each inside an import block is already merged in
https://github.com/hashicorp/terraform/pull/33932

Steps to Reproduce

  1. terraform init
  2. terraform validate

Additional Context

We have around 150 s3 buckets that we need to import into workspace. We are trying to use for_each inside an import block to import all the buckets at once and save a lot of manual work.
Really appreciate your help here

References

#33932

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnewnew issue not yet triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions