Infrastructure as Code (IaC) is the gold standard for managing infrastructure in modern cloud environments. But what if your infrastructure was built manually over months or years? Or worse, spread across different teams, with no documentation, version control, or consistent practices?
That’s where Terraformer becomes your best friend.
What is Terraformer?
Terraformer is an open-source CLI tool built by Google Cloud Platform (GCP) engineers. Its core functionality is simple but powerful:
It reads your existing infrastructure from a cloud provider and generates Terraform code
.tf
files) and state files.tfstate
), effectively reverse-engineering the setup.
You can use Terraformer to extract resources from:
Cloud providers like GCP, AWS, Azure, Alibaba
Platforms like Kubernetes, GitHub, Cloudflare, Datadog, and more
This makes it ideal for bootstrapping Terraform into existing environments that were originally built outside of Terraform.
Why terraformer over terraform import ?!
They both help to bring the existing infrastructure under the Terraforms management, but they serve different purposes.
With Terraform Import, we can import the resources one at a time, while the Terraform can be used to bulk import many resources.
It can be the really tedious to import large infra using the terraform import and its quite efficient while using the terraformer and is quite scalable also.
We have to write the terraform files manually (writing the matching terraform config) in the case of the terraform import while terraformer autogenerates the terraform files (main, variables, outputs) and terraform state files.
How Terraformer Works
Step-by-step process:
1. Connect to the Cloud: You authenticate Terraformer to your cloud account using service credentials, CLI config, or environment variables.
2. Specify Resources: You define which resources to extract using flags like --resources
or --filter
.
3. Extract Infrastructure: Terraformer queries the cloud APIs, fetches the metadata of resources, and generates Terraform code.
4. Generate Terraform Files:
- .tf
files: Human-readable resource definitions
- .tfstate
file: Current state mapping of real-world resources to Terraform
5. Optional Refactoring: You can then clean, modularize, and refactor the generated code for production use.
Example: Using Terraformer for GCP Compute Engine
Let’s say you want to export all Compute Engine instances from your GCP project.
terraformer import google \
--resources=compute_instance \
--projects=my-gcp-project \
--zone=us-central1-a
The Output generated will be like
.
├── generated/
│ └── google/
│ └── compute_instance/
│ ├── main.tf
│ ├── outputs.tf
│ ├── terraform.tfstate
│ └── variables.tf
Some Real-World Use Cases
1. Migration to Infrastructure as Code
If your infrastructure was created manually or through scripts, Terraformer accelerates the move to Terraform by providing an automated way to bootstrap IaC.
2. Disaster Recovery Planning
By codifying your current state, Terraformer helps you create reproducible environments — essential for DR strategies.
3. Cloud Auditing & Documentation
Terraformer-generated .tf
files can serve as a readable, structured representation of your infrastructure — better than screenshots and endless dashboard clicks.
4. Multi-Cloud Environment Replication
Extract infrastructure from one cloud/account/region and use it as a base to replicate the same setup elsewhere.
5. Baseline for Refactoring
Even if you don’t want to manage all infra with Terraform, Terraformer helps you get a base that you can clean, modularize, or partially adopt.
Terraformer Limitations (and Workarounds)
Limitation | Explanation | How to Overcome |
---|---|---|
Flat Code Structure | Code isn’t modular; everything in | Refactor into reusable modules post-generation |
Hardcoded Values | Project IDs, IPs, and names are hardcoded | Replace with variables and data sources |
Partial Resource Support | Not all cloud services are supported | Use |
No State Locking | Local state file can lead to drift or conflicts | Migrate to a remote backend (e.g., S3, GCS) |
Resource Noise | It grabs everything by default | Use |
Congratulations—you made it to the last!! Stay ahead; subscribe to the EzyInfra Knowledge Base for more DevOps wisdom.
Conclusion
Terraformer is a game-changer when it comes to embracing Infrastructure as Code in existing environments. It removes the barrier of starting from scratch and gives you a fast lane to modern DevOps practices. It won’t magically fix bad infrastructure design, but it will help you understand, codify, and version your infrastructure.
EzyInfra.dev – Expert DevOps & Infrastructure consulting! We help you set up, optimize, and manage cloud (AWS, GCP) and Kubernetes infrastructure—efficiently and cost-effectively. Need a strategy? Get a free consultation now!
Share this post