Interview Prep/Terraform/Import Refactoring Drift and Lifecycle

An S3 bucket was created by hand in the console and now must be managed by Terraform. How do you bring it in?

BeginnerScenarioImport Refactoring Drift and Lifecycle
Answer

Situation read → Existing resource, no code, no state entry.

What I'd do →

  1. Write the resource block that matches the bucket.
  2. Add an import block (Terraform 1.5+).
  3. Run terraform plan, adjust the code until the diff is empty, then apply.
import {
  to = aws_s3_bucket.assets
  id = "acme-assets-prod"
}
resource "aws_s3_bucket" "assets" {
  bucket = "acme-assets-prod"
}

Why → Import blocks are reviewable and plannable, unlike the one-shot terraform import command.

Interview tip → Import only writes state; you must write the code that matches.

All Terraform questions Roadmap: Terraform in production

More on Import Refactoring Drift and Lifecycle