What this thread does
The problem
Years of infrastructure were clicked together in the console or built with scripts, and nothing about it is in Terraform. terraform import one resource at a time is slow, and the config you get still needs cleanup.
What the source says
An r/Terraform thread (24 March 2026, by u/StatisticianKey7858) asked exactly this. The top answer is the honest one (do the tedious imports until done). The practical replies that follow, all reported by commenters and not run by me:
- Let the agent do the tedium, with read access only. A commenter says Claude with an MCP server can write the Terraform code and the import for a given instance ID on AWS, and adds: limit IAM so it only does reads. Another: give an AI read-only access to the resources and have it generate the import statements "for you to review and run". A third says to give it read access to the cloud platform and let it write import blocks and resource definitions, plan, check the result and iterate.
- Deny apply. A commenter using Opus 4.6 says to edit its permissions so
terraform applyis denied, maybe all ofterraformbehind a wrapper script that blocks apply, because these are live production resources. - Use
importblocks, not the CLI command. Two commenters point out that blocks go through the normal plan and apply cycle, so the import is reviewed before it happens. A third suggests afor_eachimport block driven by a variables file when the same module is imported many times. - Bulk discovery. A commenter points to HashiCorp's Terraform search and import post (Andre Faria, 1 December 2025). Per the post, it needs Terraform 1.14: a
listblock in a.tfquery.hclfile finds existing resources (its example filters EC2 instances by tag and state),terraform queryruns it, and starterimportandresourceblocks are generated (in the post, from a Generate Starter Configuration button in the HCP Terraform UI) and copied into your config. In the post's example, applying imported six instances. The post notes it supports only some AWS resources so far and that complex schemas may need manual fixes. - Alternatives named once each: rebuild the stuff in Terraform and migrate workloads, then delete the old one (also: take console access away from humans); commercial import tools (their makers say so).
How to describe it to your agent
Using the read-only AWS profilereadonly, list the unmanaged<resource type>in<region>. For each, write animportblock and a minimalresourceblock inimports.tf, then runterraform planand fix the config until the plan shows no changes except the imports. Do not runterraform applyorterraform destroy. Show me the plan.
Terraform's own docs describe terraform plan -generate-config-out=generated.tf, which drafts resource code for import blocks. The docs call configuration generation experimental (introduced in v1.5), say the path must be a new file because an existing one causes an error, warn that complex schemas can fail with a conflicting-arguments error, and say the generated code is a starting template to review before apply. Check the page for your version.
Mistakes to check
- Using an admin or write-capable credential for the discovery step.
- Accepting a plan that shows anything other than "import" for the resources you meant to adopt: changes or replacements mean the written config does not match reality.
- Importing everything before deciding who may still touch resources in the console; drift reappears.
- Skipping a state backup and remote state before you start (see the thread on what happened when an agent ran destroy against missing state).
Limits
Not run by me. The agent-assist advice comes from a handful of commenters; none posted a transcript. Terraform search support depends on your provider.
Sources
- HashiCorp blog post "Terraform search and import" by Andre Faria, 1 December 2025 (<https://www.hashicorp.com/en/blog/terraform-search-and-import-find-resources-and-bring-them-into-terraform>), read directly. Checked: Terraform 1.14, a list block in a search.tfquery.hcl file, terraform query, the EC2 example filtered by tag and state, six instances found and imported, support limited to a select group of AWS resources, and manual fixes for complex schemas.
- Terraform docs page on generating configuration for imports (<https://developer.hashicorp.com/terraform/language/import/generating-configuration>), read directly. Checked: the generate-config-out flag and its caveats.
- Not checked here, the r/Terraform thread, its counts and every commenter's advice (Reddit not opened; the advice is reported as commenters' claims, not verified), and the thread on agents running destroy.
Started from a post by @StatisticianKey7858, packaged by the editor. Original post