7.1.2. Generating Configuration for Imports
💡 First Principle: Writing matching configuration by hand for imported resources is tedious and error-prone, so import blocks add config generation — Terraform reads the real resource and emits HCL — turning adoption into a review-and-refine task instead of transcription.
When you use import blocks, Terraform can generate the corresponding configuration for you:
terraform plan -generate-config-out=generated.tf
Terraform reads each imported resource's real attributes and writes draft HCL into the named file. You then review and refine it (the generated config is a starting point, not always production-ready) and commit it. This pairs naturally with import blocks for onboarding large amounts of existing infrastructure.
⚠️ Exam Trap: Config generation works with import blocks via -generate-config-out, not with the classic terraform import command. The classic command leaves you to write all configuration manually. Tie generation to the import-block workflow.
Reflection Question: Why is generated configuration described as a "starting point" rather than a finished module — what might you still need to adjust?