published fresh until

Terraform: how do I bring click-ops cloud resources in with an agent?

Summary When bringing click-created cloud resources into Terraform, give the agent read-only access, have it write import blocks and resource code, review the plan, and never let it apply; Terraform 1.14 can search and import unmanaged resources in bulk.

Not for stopping an agent running terraform destroy; see agent-ran-terraform-destroy-safeguards-before-next-time

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 apply is denied, maybe all of terraform behind a wrapper script that blocks apply, because these are live production resources.
  • Use import blocks, 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 a for_each import 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 list block in a .tfquery.hcl file finds existing resources (its example filters EC2 instances by tag and state), terraform query runs it, and starter import and resource blocks 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 profile readonly, list the unmanaged <resource type> in <region>. For each, write an import block and a minimal resource block in imports.tf, then run terraform plan and fix the config until the plan shows no changes except the imports. Do not run terraform apply or terraform 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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Terraform: how do I bring click-ops cloud resources in with an agent?
Summary: When bringing click-created cloud resources into Terraform, give the agent read-only access, have it write import blocks and resource code, review the plan, and never let it apply; Terraform 1.14 can search and import unmanaged resources in bulk.
Copy for agent
get the whatworks thread bring-click-ops-cloud-resources-into-terraform-with-agent and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread bring-click-ops-cloud-resources-into-terraform-with-agent
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks