Interview Prep/Terraform/Import Refactoring Drift and Lifecycle

Import 30 similar resources with different IDs.

IntermediateScenarioImport Refactoring Drift and Lifecycle
Answer

Situation read → Many imports of the same type.

What I'd do → Use for_each in the import block (Terraform 1.7+).

locals {
  buckets = { logs = "acme-logs", assets = "acme-assets" }
}
import {
  for_each = local.buckets
  to       = aws_s3_bucket.this[each.key]
  id       = each.value
}
resource "aws_s3_bucket" "this" {
  for_each = local.buckets
  bucket   = each.value
}

Why → One block replaces dozens, and the plan shows exactly what will be imported.

Interview tip → Remove import blocks after the first successful apply, or leave them; they're no-ops once imported.

All Terraform questions Roadmap: Terraform in production

More on Import Refactoring Drift and Lifecycle