The Problem Every Cloud Engineer Knows Too Well
You've just finished configuring a complex AWS environment — VPCs, security groups, RDS instances, IAM roles — all through the AWS Console. It works perfectly. Now someone asks, "Can you put that in Terraform?"
Cue the dread.
Manually reverse-engineering live AWS infrastructure into clean, idiomatic Terraform code is tedious, error-prone, and time-consuming. But it doesn't have to be. In this guide, we'll compare three practical methods to generate Terraform code from the AWS Console, from raw CLI tools to AI-powered visual builders — so you can pick the right approach for your team.
Why Generating Terraform from AWS Is Hard
Before diving into solutions, it helps to understand why this is a real engineering challenge:
AWS Console is stateful; Terraform is declarative. The Console lets you click into existence; Terraform needs explicit resource definitions, dependencies, and relationships.
Resource drift is invisible. Resources modified outside of Terraform leave your IaC out of sync with reality.
terraform importonly gets you halfway. It pulls state but doesn't generate the.tfconfiguration files you actually need.AWS has hundreds of resource types, each with dozens of configurable attributes — getting them all right manually is a nightmare.
The good news: several tools now exist to close this gap. Let's compare them.
Method 1: AWS CLI + terraform import (Manual, Free)
How It Works
This is the traditional approach. You use the AWS CLI to inspect existing resources, then hand-write or copy-paste the Terraform resource blocks, and finally use terraform import to sync the state.
Step-by-Step
1. Identify the resource in AWS Console
Navigate to the resource — say, an S3 bucket named my-app-assets — and note its identifier (ARN, name, or ID).
2. Write the Terraform resource block manually
resource "aws_s3_bucket" "my_app_assets" {
bucket = "my-app-assets"
# Additional attributes filled in manually
}
3. Run terraform import
terraform import aws_s3_bucket.my_app_assets my-app-assets
This populates terraform.tfstate but does not generate .tf files.
4. Read state to fill in attributes
terraform show -json | jq '.values.root_module.resources[] | select(.type=="aws_s3_bucket")'
Use the output to manually complete your resource block.
Pros
Free, no extra tooling
Works with any Terraform version
Full control over output
Cons
Does not auto-generate
.tfconfiguration filesTedious for complex or multi-resource environments
High risk of missed attributes (versioning, policies, tags, CORS, etc.)
Each resource type requires its own deep knowledge of the Terraform schema
Best for: Engineers who need to import 1–3 well-understood resources into an existing codebase.
Method 2: terraformer — Open Source Reverse-Engineering Tool
How It Works
Terraformer is an open-source CLI tool by Google that can scan your AWS account and automatically generate Terraform .tf files and state files for existing resources.
Step-by-Step
1. Install Terraformer
brew install terraformer
# or download the binary from GitHub releases
2. Install the AWS provider plugin
terraform init # in a directory with a basic AWS provider config
3. Run Terraformer against your AWS account
terraformer import aws \
--resources=vpc,subnet,security_group,s3,rds \
--regions=us-east-1 \
--profile=my-aws-profile
4. Review the generated output
Terraformer creates a structured folder with .tf files and a terraform.tfstate per resource type:
generated/
aws/
vpc/
main.tf
outputs.tf
provider.tf
terraform.tfstate
s3/
main.tf
...
Pros
Generates actual
.tfconfiguration filesSupports 100+ AWS resource types
Handles multi-resource environments
Open-source and free
Cons
Generated code is often messy — hardcoded values, no variables, no modules
Frequently produces deprecated or non-idiomatic Terraform syntax
Requires significant manual cleanup before it's production-ready
State files from different runs are hard to merge
Not actively maintained for the latest AWS resource types
Can generate hundreds of resources you didn't want
Best for: Brownfield migrations where you need a rough starting point for a large environment and are prepared to invest time in cleanup.
Method 3: CloudOps AI Visual Builder (AI-Assisted, Recommended)
How It Works
CloudOps AI takes a fundamentally different approach. Instead of reverse-engineering everything blindly, it gives you a visual wizard that lets you select the specific resources you care about, then uses AI to generate clean, modular, production-ready Terraform code.
Step-by-Step
1. Connect your AWS Account
Link your AWS account via read-only IAM role — CloudOps AI never needs write permissions to generate code.
2. Visualize your existing infrastructure
CloudOps AI scans your account and renders a live diagram of your current resources — VPCs, subnets, EC2s, RDS clusters, ALBs, Lambda functions, and more.
3. Select what you want to codify
Click on the resources you want to export. You can select an entire VPC, a specific application stack, or just a handful of security groups. You're in control — no "import everything and clean up later."
4. Configure your preferences
The wizard asks smart questions:
Terraform version (0.14+, 1.x)
Backend type (S3, Terraform Cloud, local)
Variable extraction (what should be parameterized?)
Module structure (flat, or organized by component?)
Tagging strategy
5. Generate and review
CloudOps AI produces:
Clean
.tfresource definitions using current Terraform syntaxA
variables.tfwith sensible defaultsAn
outputs.tfexposing key attributes
A README.md documenting each resource
A ready-to-use backend.tf
# Example output: CloudOps AI-generated VPC
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
enable_dns_support = true
enable_dns_hostnames = true
tags = merge(var.common_tags, {
Name = "${var.project_name}-vpc"
})
}
Notice: no hardcoded values, no drift-prone magic strings. Variables and tags are extracted automatically.
6. Export or push to Git
Download the code as a ZIP, or have CloudOps AI open a pull request directly to your GitHub or GitLab repository.
Pros
Clean, idiomatic, production-grade Terraform output
Visual resource selection — no unintended sprawl
AI handles variable extraction and module organization
Supports remote backends out of the box
Generates documentation alongside code
Continuously updated for latest AWS resource types
Saves hours of manual work per environment
Cons
Paid product (free tier available)
Requires AWS account connection via IAM
AI suggestions may need review for very complex or non-standard configurations
Best for: Teams that need production-ready Terraform fast, are migrating a real workload, or want to establish IaC without the pain of manual reverse-engineering.
Side-by-Side Comparison
terraform import (Manual) does not generate .tf files and requires you to manually write the Terraform configuration. The code quality depends entirely on manual effort, variable extraction is manual, and module structure must also be created manually. Resource selection is done one resource at a time, there is no Git integration or documentation support, and support for the latest resource types depends on your own knowledge and maintenance. It is free to use, but the time to get production-ready code usually takes hours to days.
Terraformer (OSS) automatically generates .tf files and supports many AWS resources across types and regions. However, the generated code is often messy, outdated, and requires significant cleanup before production use. It does not support variable extraction, uses mostly flat file structures, and lacks Git integration and documentation generation. Support for newer AWS resource types can be inconsistent. It is also free, but still takes hours plus cleanup time before the code becomes usable.
CloudOps AI generates clean, production-ready .tf files with idiomatic Terraform syntax. It automatically handles variable extraction, supports configurable module structures, and allows visual resource selection instead of importing everything blindly. It includes Git integration, auto-generated documentation, and continuously updated support for the latest AWS resource types. It follows a freemium pricing model and usually reduces time to usable code from hours to just minutes.
Which Method Should You Use?
Choose manual terraform import if you're onboarding a single, well-understood resource into an existing Terraform codebase and don't want to introduce new tooling.
Choose Terraformer if you need to bulk-generate a rough scaffold for a large brownfield environment, and your team has bandwidth to heavily clean up and refactor the output.
Choose CloudOps AI if you want production-ready code fast — especially for new projects, client deliverables, team onboarding, or any situation where code quality and time-to-value matter.
Bonus: Preventing the Problem in the Future
The best Terraform is code that was always Terraform — not retrofitted from the Console.
Here are habits that keep your IaC clean going forward:
1. Enforce a "Terraform-first" policy. Any new infrastructure should be provisioned through Terraform, not the Console. Use AWS Service Control Policies (SCPs) to restrict console-based resource creation in production.
2. Use CloudOps AI's live drift detection. Get alerts when someone creates resources outside of Terraform, before they become technical debt.
3. Standardize on modules. Use verified modules from the Terraform Registry for common patterns (VPC, EKS, RDS) rather than raw resource blocks. This reduces the surface area of manual configuration.
4. Implement state locking. Use an S3 backend with DynamoDB locking to prevent concurrent state corruption:
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-state-lock"
encrypt = true
}
}
Final Thoughts
Generating Terraform from the AWS Console is a real pain — but it's a solvable one. The right tool depends on your situation:
Quick one-off imports → manual
terraform importBulk brownfield scaffold → Terraformer
Production-ready code, fast → CloudOps AI
If you're serious about Infrastructure as Code at scale, the visual + AI approach isn't just a convenience — it's a multiplier for your entire team's productivity.
Ready to optimise your cloud operations?
CloudOps AI gives your team AI-powered architecture, FinOps, and DevSecOps in one platform.
Start for free →Frequently Asked Questions
Can Terraform automatically generate code from existing AWS resources?
Not natively. terraform import updates state but doesn't write .tf files. Tools like Terraformer or CloudOps AI are needed to generate actual configuration code.
Is Terraformer still maintained in 2024?
Terraformer is open-source but has inconsistent maintenance. Some resource types are up-to-date; others generate deprecated syntax. Always review generated code carefully.
Does CloudOps AI require write access to my AWS account?
No. CloudOps AI uses a read-only IAM role to scan and visualize resources. It never modifies your AWS environment.
What Terraform version does CloudOps AI support?
CloudOps AI generates code compatible with Terraform 0.14 through the latest 1.x versions, with configurable syntax options.
How do I handle sensitive values like passwords and secrets in generated Terraform?
CloudOps AI flags sensitive attributes and replaces them with variable references, preventing secrets from being hardcoded in your codebase. Always use a secrets manager like AWS Secrets Manager or HashiCorp Vault for runtime values.
Written by
Abhay SinghCloud Architect
Cloud Architect and DevOps specialist with 10+ years of experience in AWS and Azure.
More articles by Abhay Singh →