Terraform interview question · Most asked

How do you bring existing infrastructure under Terraform management?

Summary

Use import blocks (Terraform 1.5+) in configuration, which are planned and reviewed like any change, optionally with terraform plan -generate-config-out=generated.tf to generate a starting configuration for the imported resources. The older terraform import CLI command imports one resource at a time into state without configuration.

Longer Answer

Workflow: write import blocks with the target address and real ID, generate or hand-write the resource configuration, run plan until it shows no changes (meaning configuration matches reality), then apply to record it in state, and clean up the generated code into modules. Tools such as Terraformer or provider-specific exporters help with large estates. Import is also how you recover when a resource exists but state lost track of it.

Key Points

  • import blocks (1.5+) are reviewable.
  • Generate config with -generate-config-out.
  • Iterate until plan shows no changes.
  • Clean up into modules.

More most-asked Terraform questions

← All Terraform questions