Interview Prep/Terraform/State Internals

Can you import resources into `for_each` addresses, or into modules?

IntermediateConceptState Internals
Answer

Yes. The to address can include a key or module path, and from Terraform 1.7 import blocks accept for_each.

import {
  for_each = { a = "subnet-0abc", b = "subnet-0def" }
  to       = aws_subnet.private[each.key]
  id       = each.value
}
All Terraform questions Roadmap: Terraform in production

More on State Internals