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
}
More on State Internals
What does the state file contain?BeginnerWhat is the difference between local and remote state?BeginnerHow do you configure the S3 backend?BeginnerWhat is state locking and why does it matter?IntermediateHow does S3-native locking work and how does it replace DynamoDB?AdvancedHow do you inspect resources in state?Beginner