DEV Community

Cover image for AWS Import/Export infrastructure as code (CloudFormation | Terraform)
Exequiel Barrirero for AWS Community Builders

Posted on • Originally published at Medium

AWS Import/Export infrastructure as code (CloudFormation | Terraform)

Based on our Infrastructure as Code (IaC) experience at Binbash ( we found several ways to translate existing manually deployed (from Web Console UI) AWS infra to Cloudformation (CF) and / or Terraform (TF) code.

AWS Cloudformation Templates

aws cloudformation overview

CF-#1 | AWS CloudFormation native import feature

Introduced feature (since Nov 2019) that allows to Import existing resources into a CloudFormation stack

For more info check:

aws cloudformation workflow

CF-#2 | aws cli & manually translate to CF

Execute $aws service_name_here describe for each element that make up your stack, eg for RDS Database Stack:

  • RDS Instance -> Type: AWS::RDS::DBInstance,
  • RDS (EC2) SG -> Type: AWS::EC2::SecurityGroup,
  • RDS Subnet Group -> Type: AWS::RDS::DBSubnetGroup and
  • RDS DB Param Group -> Type: AWS::RDS::DBParameterGroup

Afterwards manually translate to CF based on the outputs obtained from the aws cli for each of the components. This approach usually requires more experience in both AWS and CF, but the templates that you are creating can be structured and designed under best practices, fully parameterized (Sub, Ref, Join, Fn::GetAtt:, Fn::ImportValue), modular, applying conditions . As a result your 1st iteration would probably be close to the final state of the templates

Very interesting reference examples:

aws cloudformation template workflow

CF-#3 | Former2

Former2 allows you to generate Infrastructure-as-Code outputs from your existing resources within your AWS account. By making the relevant calls using the AWS JavaScript SDK, Former2 will scan across your infrastructure and present you with the list of resources for you to choose which to generate outputs for.

Terraform Code / Modules

cloudcraft + +

TF-#1 | CloudCraft +

Map your reality, don't waste time producing static documentation that is outdated as soon as you publish.

Cloudcraft Live instantly analyzes all the service relationships of your AWS environment, and reverse engineers a complete system architecture diagram.

Their powerful auto-layout and advanced AWS account scanning capabilities are also available to you as an API. Then via the "Terraform code export" ( will be generating infrastructure as Terraform configurations from visual diagrams created using Cloudcraft.

cloudcraft console

Cloudcraft terraform code export

TF-#2 |

With you could import your cloud infrastructure
and turn AWS environments into actionable visual Terraform infrastructure-as-code IaC.

They named this feature as "Terraform Reverse" , which allows users to import an infrastructure from your cloud credentials. :ledged: NOTE: This feature is in Beta and will be released soon for everyone.

The complete doc could be found here

brainboard terraform reverse

Importing your infrastructure with from AWS

brainboard terraform diagram diagram + terraform code

Discussion (0)