Listen to this Post

Using Infrastructure as Code (IaC) tools like Terraform is great, but many teams already have existing infrastructure and don’t want to delete it all just to start using Terraform. This is where Terraformer can help—it allows you to import existing cloud infrastructure into Terraform state files.
Terraform maintains a state file containing all the resources it manages. Typically, this includes only resources provisioned via Terraform. When you run terraform apply, Terraform compares the state file with the actual infrastructure and applies necessary changes.
How Terraformer Works
Terraformer reverse-engineers existing cloud resources (AWS, GCP, Azure, etc.) and generates Terraform configuration files (.tf) along with the state file. This avoids manual recreation of infrastructure just to adopt IaC.
Installation Steps
1. Install Terraformer (requires Go):
git clone https://github.com/GoogleCloudPlatform/terraformer.git cd terraformer go install
2. AWS Example (Import EC2 instances):
terraformer import aws --resources=ec2 --regions=us-east-1
3. Generate Terraform Files:
terraform init terraform plan
You Should Know: Essential Terraform & Terraformer Commands
Terraform Basics
- Initialize Terraform:
terraform init
- Plan changes:
terraform plan
- Apply changes:
terraform apply
- Destroy resources:
terraform destroy
Terraformer-Specific Commands
- List supported providers:
terraformer help
- Import AWS S3 buckets:
terraformer import aws --resources=s3 --regions=us-west-2
- Filter resources by name:
terraformer import aws --resources=ec2 --filter="Name=instance_id;Value=i-12345678"
Advanced Usage
- State Management:
terraform state list List resources in state terraform state show aws_instance.example Inspect a resource
- Workspaces (for multiple environments):
terraform workspace new dev terraform workspace select dev
What Undercode Say
Terraformer bridges the gap between manual cloud setups and IaC adoption. While it doesn’t generate modular Terraform code by default, combining it with Terragrunt or manual refactoring can optimize output. For teams managing legacy systems, Terraformer is a must-try.
Expected Output:
After running `terraformer import`, expect:
– `main.tf` (generated Terraform config)
– `terraform.tfstate` (imported state)
– `provider.tf` (cloud provider setup)
Prediction
As cloud environments grow, tools like Terraformer will integrate AI-assisted refactoring (e.g., auto-modularizing code). Expect tighter coupling with DevOps pipelines for seamless IaC migration.
Reference: Terraformer: Reverse Engineering Infrastructure as Code
References:
Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


