How do you import a large existing environment efficiently?
IntermediateProductionRefactoring, Migration and Drift
Answer
Use import blocks with terraform plan -generate-config-out=generated.tf to draft configuration, then clean it up into modules and variables (generated code is verbose and hardcoded). Tools like Terraformer or aws2tf can inventory a region. Import in layers (network first), validate with empty plans and avoid importing resources you plan to retire.
More on Refactoring, Migration and Drift
What is your workflow for refactoring Terraform safely?IntermediateHow do you rename a resource inside a shared module without breaking consumers?AdvancedHow do you split one state into two without downtime?AdvancedHow do you merge two states?IntermediateHow do you upgrade a major version of the AWS provider?AdvancedHow do you upgrade the Terraform CLI across many stacks?Intermediate