KryptonCloud

aws-terraformizando: from a console-built AWS account to Terraform, without touching a thing

How to bring a console-built AWS account into Terraform safely: aws-terraformizando reads everything, writes import blocks and validates with plan.

PFBy Paulo Frugis· 4 min read

Also available in: 🇮🇹 Italiano · 🇧🇷 Português

Every company that grew on AWS has a slice of infrastructure that was born in the console: the VPC created in a rush for a customer, the security group tweaked at midnight, the subnet “someone” added. It works, but nobody knows exactly what exists, and reproducing it in another region or account turns into archaeology.

Moving that environment to Terraform solves the problem, but the path is intimidating. Rewriting everything by hand is slow and error-prone, and one mistake can recreate or delete a production resource. That is why we built aws-terraformizando, an open-source tool now available on Krypton Cloud’s GitHub.

What aws-terraformizando is

It is a Python CLI that reads an existing AWS account and generates reliable Terraform code from the real environment, with documentation and an infrastructure diagram. It runs interactively, asking for what is missing step by step, or in non-interactive mode for automation.

The flow has three main commands:

  • tfz discover connects to the account, lists every resource and shows a coverage report.
  • tfz generate lets you choose what to convert and generates the Terraform code.
  • tfz validate runs terraform fmt, validate, tflint and plan on the generated code.

Read-only by design

The project’s first rule is that the tool never changes anything in the customer’s account. That is not just a promise in the README:

  • A guard installed on the boto3 session runs before each request is signed. If the operation is not a read, or if it reads a secret, such as GetSecretValue or decrypted SSM parameters, the call is blocked and nothing leaves the machine.
  • A test walks the models of every service in the catalog and ensures no write operation gets through the policy.
  • On the Terraform side, only init, plan, show, validate, fmt, version and providers are allowed. apply, destroy, import and -auto-approve are refused before running.
  • Static credentials in the environment are removed: Terraform uses only the validated profile, and the tool checks that the account is the same one used for discovery.

Full discovery, at no cost, with nothing to enable

Many inventory tools depend on AWS Config or Resource Explorer, which must be enabled and, in Config’s case, are billed per use. aws-terraformizando only uses each service’s list APIs, the same as the AWS CLI, in three layers:

  1. Generic sweep: every List, Describe or Get operation with no required parameters, across all services, so nothing is left out.
  2. Type catalog: 143 resource types across 33 services, with precise rules for listing, identifier, ARN and the matching Terraform type.
  3. Cross-check: the free Resource Groups Tagging API points out tagged resources the previous layers did not find.

Nothing is left out silently: the report shows what is convertible, what has no converter yet (with the reason), what was denied by permissions and what is unclassified. On the first real account we ran it on, AWS’s own public catalogs (Bedrock models, Security Hub controls, SSL policies) made up 94% of the items and buried the customer’s resources. Today they are filtered out and only counted separately. On that same account, timeout tuning and skipping unavailable services took discovery from 18 minutes down to 4 minutes 19 seconds.

How the Terraform is generated

Instead of reinventing each resource’s HCL, the tool lets the official AWS provider write the code:

  1. It writes native import {} blocks for each selected resource.
  2. It runs terraform plan with -generate-config-out, which is read-only.
  3. It uses terraform validate -json itself to fix what the generator gets wrong. One example: the generator writes both availability_zone and availability_zone_id on a subnet, and the provider refuses the two together.
  4. It post-processes the code:
    • literal IDs become references (vpc_id = aws_vpc.prod.id) without creating cycles;
    • zones and CIDRs move to variables in a per-region .tfvars;
    • sensitive values become sensitive variables;
    • route and rule lists become clean blocks;
    • each service goes to its own file.

Selecting a subnet brings its VPC along; selecting a route table brings the internet gateway and the associations. Everything shows up in a final list you confirm before generation.

Validation: it is only done when the plan changes nothing

The success criterion is objective. In each region, terraform plan must end with N to import, 0 to add, 0 to change, 0 to destroy. If the generated code does not match the real environment exactly, the differences go to a validation report, with the resource and the attributes that would change.

Each run also produces a README (in Portuguese for now) with a Mermaid diagram of each region’s network, the versions used and instructions to replicate the environment: copy the region directory, adjust the .tfvars, delete imports.tf and use a separate state.

Where the project stands and what comes next

Discovery and the coverage report are done. Code generation started with Tier 1, networking: VPC, subnets, route tables, internet and NAT gateways, Elastic IPs, security groups, network ACLs, endpoints and peering. The generated code already passes a real terraform validate. The next step is validating with plan on more real accounts, followed by the compute, identity and security, data, serverless, containers, DNS and edge tiers.

The repository is public under the Apache 2.0 license. main is protected and every change goes through a pull request with tests. Anyone can fork it and open issues with bugs, missing resource types or ideas.

How Krypton can help

Bringing a whole account into infrastructure as code takes more than generating files: it means organizing state, pipelines and the team’s process. With Krypton DevOps, we walk that path with you, from inventory to the first deploy through the pipeline. Want to talk about your environment? Talk to us.

Sources

Frequently asked questions

How do I turn existing AWS infrastructure into Terraform?+

The safest path is to import resources without recreating them: list what exists, write import blocks for each resource, let Terraform generate the configuration with terraform plan -generate-config-out, and adjust the code until the plan shows imports only. aws-terraformizando automates these steps.

Does aws-terraformizando change anything in my AWS account?+

No. The tool is read-only: it only runs List, Describe and Get operations, blocks writes and secret reads before they are sent, and never runs terraform apply. Applying the code is your decision.

Do I need to enable AWS Config or Resource Explorer?+

No. Discovery only uses each service's list APIs, the same as the AWS CLI, plus the Resource Groups Tagging API as a cross-check. Nothing needs to be enabled and nothing is billed per use.

Which resources can aws-terraformizando already convert to Terraform?+

Discovery has covered the whole account since the first version. Code generation starts with Tier 1, networking: VPC, subnets, route tables and associations, internet and NAT gateways, Elastic IPs, security groups, network ACLs, endpoints and peering. Resources without a converter yet show up in the report as not convertible, with the reason.

Is aws-terraformizando free?+

Yes. The code is open source under the Apache 2.0 license, on Krypton Cloud's GitHub. Anyone can use it, fork it and open issues.

#Terraform#AWS#Infrastructure as code#Terraform import#Open source#DevOps
Share:

Read next

Want to put this to work in your company?

Krypton turns AI and cloud news into results, with costs under control and human approval at every step.