Terraformer Magic: Convert Your AWS Setup into Terraform Code in Minutes

Manually created infrastructure? No problem. With Terraformer, you can generate Terraform code for existing AWS resources in just a few commands. Let’s see how to set it up on an Amazon Linux EC2 instance.
Install Terraform
sudo yum install unzip -y
wget https://releases.hashicorp.com/terraform/1.8.4/terraform_1.8.4_linux_amd64.zip
unzip terraform_1.8.4_linux_amd64.zip
sudo mv terraform /usr/local/bin/
terraform version
Install Terraformer
wget https://github.com/GoogleCloudPlatform/terraformer/releases/download/0.8.24/terraformer-all-linux-amd64 -O terraformer
chmod +x terraformer
sudo mv terraformer /usr/local/bin/
Import EC2 Instances with One Command
terraformer import aws --resources=ec2_instance --regions=us-east-1
This pulls all EC2 instances from us-east-1 and generates Terraform files for you.
Output Structure
generated/
└── aws/
└── ec2_instance/
├── main.tf
├── outputs.tf
└── terraform.tfstate
Consolidate All Resources into a Single Terraform Project
By default, Terraformer creates separate folders and state files per resource type. To manage everything cleanly under one project, follow these steps:
Make a new folder for your Terraform project and Move All Terraform Files
mkdir terraform
cd terraform
cp ../generated/aws/*/*.tf .
terraform init
Re-import Resources into the New Project
terraform import <resource_type>.<resource_name> <resource_identifier>
Repeat for each resource using the correct identifiers.
Final Result
All resources are now in a single terraform
folder with one terraform.tfstate
file — making it easier to manage, version, and collaborate with your team.