ScriptsApr 16, 2026·3 min read

Terraformer — Reverse-Engineer Existing Cloud Infrastructure to Terraform

Terraformer is a CLI tool by Google that reads live cloud resources from AWS, GCP, Azure, and 30+ other providers and generates corresponding Terraform HCL files and state, enabling infrastructure-as-code adoption on brownfield environments.

TL;DR
Terraformer reads live cloud resources and generates Terraform HCL files and state automatically.
§01

What it is

Terraformer is a CLI tool originally developed at Google that reads existing cloud infrastructure and generates corresponding Terraform HCL configuration files and state files. It supports AWS, GCP, Azure, and over 30 additional providers. The primary use case is adopting infrastructure-as-code on brownfield environments where cloud resources were created manually or through other tools.

Terraformer targets DevOps engineers and platform teams who need to bring existing cloud infrastructure under Terraform management without manually writing HCL for every resource.

§02

How it saves time or tokens

Manually writing Terraform configurations for existing infrastructure is tedious and error-prone. A typical AWS account might have hundreds of resources across VPCs, security groups, EC2 instances, RDS databases, and IAM policies. Terraformer scans all resources for a given provider and service, then generates the HCL files and imports the state in one command. This turns weeks of manual work into minutes.

For AI-assisted infrastructure management, Terraformer's output provides a machine-readable snapshot of your cloud infrastructure that an LLM can analyze for cost optimization, security review, or architecture documentation.

§03

How to use

  1. Install Terraformer: download the binary from GitHub releases or use brew install terraformer on macOS.
  2. Ensure you have the corresponding Terraform provider installed and valid cloud credentials configured (AWS CLI, gcloud, etc.).
  3. Run Terraformer to import resources: terraformer import aws --resources=vpc,subnet,sg --regions=us-east-1. The generated HCL and state files appear in a generated/ directory.
§04

Example

# Import all AWS VPC resources in us-east-1
terraformer import aws \
  --resources=vpc,subnet,security_group,route_table \
  --regions=us-east-1 \
  --profile=production

# Output structure:
# generated/
#   aws/
#     vpc/
#       vpc.tf
#       terraform.tfstate
#     subnet/
#       subnet.tf
#       terraform.tfstate

Each resource type gets its own directory with the generated HCL and a corresponding state file.

§05

Related on TokRepo

§06

Common pitfalls

  • Terraformer generates one state file per resource type. You likely need to reorganize the generated code and merge state files into your team's existing Terraform structure.
  • Generated HCL uses hard-coded IDs and ARNs. You should refactor the output to use variables, data sources, and module references for maintainable code.
  • Some resource types have complex dependencies that Terraformer may not fully capture. Review the generated code for missing cross-references between resources.

Frequently Asked Questions

Which cloud providers does Terraformer support?+

Terraformer supports AWS, GCP, Azure, Kubernetes, GitHub, Datadog, Cloudflare, and over 30 other providers. Each provider has its own set of importable resource types. Check the Terraformer README for the full list.

Does Terraformer modify existing infrastructure?+

No. Terraformer is read-only. It queries cloud APIs to discover resources and generates Terraform files locally. It never creates, modifies, or deletes any cloud resources.

Can I import all resources at once?+

Yes. Use --resources=* to import all supported resource types for a provider. However, this can be slow for large accounts and may generate a large amount of code. Start with specific resource types you want to manage first.

How do I integrate the generated code with existing Terraform?+

After Terraformer generates the HCL and state, you typically refactor the code into your existing module structure, replace hard-coded values with variables, and use terraform state mv to merge state files into your workspace.

Is Terraformer still actively maintained?+

Terraformer is a Google-initiated open-source project. Community contributions continue, though some provider support may lag behind the latest Terraform provider versions. Check the repository for recent activity on your specific provider.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets