Sign inSign up

jeffernz/extract-cf2tf

By jeffernz

Updated over 1 year ago

A Tool to extract CloudFormation stack resources to Terraform configuration files

Image
0

873

jeffernz/extract-cf2tf repository overview

CloudFormation Stack to Terraform Importer

Docker Pulls

A tool to convert existing AWS CloudFormation stacks to Terraform import statements, variables, and outputs.

Features

  • Generates Terraform import statements for CloudFormation resources
  • Converts CloudFormation parameters to Terraform variables
  • Converts CloudFormation outputs to Terraform outputs
  • Handles special resource types that need specific ID formats
  • Supports debug output for troubleshooting

Usage

Run the following command for the help menu:

docker run jeffernz/extract-cf2tf:latest  --help
usage: extract-cf2tf.py [-h] [--region REGION] [--imports-output IMPORTS_OUTPUT]
                        [--variables-output VARIABLES_OUTPUT]
                        [--outputs-output OUTPUTS_OUTPUT]
                        [--skipped-output SKIPPED_OUTPUT] [--debug]
                        [--list-mappings] [--no-imports] [--no-variables]
                        [--no-outputs]
                        stack_name

Generate Terraform import statements from CloudFormation stack resources

positional arguments:
  stack_name            Name of the CloudFormation stack

optional arguments:
  -h, --help            show this help message and exit
  --region REGION       AWS region (default: us-east-1)
  --imports-output IMPORTS_OUTPUT
                        Output file name for imports (default: imports.tf)
  --variables-output VARIABLES_OUTPUT
                        Output file name for variables (default: variables.tf)
  --outputs-output OUTPUTS_OUTPUT
                        Output file name for outputs (default: outputs.tf)
  --skipped-output SKIPPED_OUTPUT
                        Output file for skipped resources (default: skipped_resources.json)
  --log-level {debug,info,warning,error}
                        Set the logging level (default: info)
  --list-mappings       List all available CloudFormation to Terraform mappings
  --no-imports          Skip generation of import statements
  --no-variables        Skip generation of variable declarations
  --no-outputs          Skip generation of output declarations

Extracting a CloudFormation Stack

You will need AWS credentials to run this tool. You can provide your credentials using the following methods:

Navigate to your project codebase where you want to set up your Terraform configuration files. Then to process a CloudFormation stack, you can use one of the following commands:

With Environment Variables
docker run \
    -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e AWS_REGION \
    jeffernz/extract-cf2tf:latest  "<STACK_NAME> --region <REGION>"
With an Environment File
docker run --env-file "<PATH TO YOUR ENV FILE>" \
  -v "$(pwd):/src" \
  -w /src \
  "jeffernz/extract-cf2tf:latest" "<STACK_NAME> --region <REGION>"
This will generate the following files:
  • imports.tf - Terraform import statements
  • variables.tf - Terraform variable declarations (Only if there are parameters in your stack)
  • outputs.tf - Terraform output declarations (Only if there are outputs in your stack)
  • skipped_resources.json - Resources that could not be mapped

Generating the Terraform resources

Once the terraform imports.tf file is generated, we need to generate the Terraform resources. You can generate the Terraform resources in your project by executing the following command:

terraform init
terraform plan -generate-config-out="main.tf"

LICENSE

Copyright © 2025 Jeffery Fernandez. All Rights Reserved.

This software and associated documentation files (the "Software") are the proprietary property of Jeffery Fernandez and are protected by copyright law and international treaty provisions. Unauthorized reproduction, distribution, modification, or use of this Software, in whole or in part, is strictly prohibited.

No part of this Software may be reproduced, distributed, transmitted, displayed, published, or broadcast in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise without the prior written permission of the copyright owner.

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Tag summary

Content type

Image

Digest

sha256:e42381081

Size

49.9 MB

Last updated

over 1 year ago

docker pull jeffernz/extract-cf2tf