Interview Prep/Terraform/Import Refactoring Drift and Lifecycle

You must adopt 200 existing resources and don't want to write all the HCL by hand.

IntermediateScenarioImport Refactoring Drift and Lifecycle
Answer

Situation read → Large brownfield adoption.

What I'd do →

  1. List the resources by service and tag; script the import blocks (ID discovery with the AWS CLI).
  2. Run terraform plan -generate-config-out=generated.tf to draft the HCL.
  3. Clean the generated code: drop computed attributes, replace hardcoded IDs with references, extract variables.
  4. Iterate until plan shows no changes, then refactor into modules.

Why → Generated config is a starting point and is often noisy; the empty plan is the acceptance test.

Interview tip → Do it in small batches grouped by dependency, not all 200 at once.

All Terraform questions Roadmap: Terraform in production

More on Import Refactoring Drift and Lifecycle