A Tool to extract CloudFormation stack resources to Terraform configuration files
873
A tool to convert existing AWS CloudFormation stacks to Terraform import statements, variables, and outputs.
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
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:
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>"
docker run --env-file "<PATH TO YOUR ENV FILE>" \
-v "$(pwd):/src" \
-w /src \
"jeffernz/extract-cf2tf:latest" "<STACK_NAME> --region <REGION>"
imports.tf - Terraform import statementsvariables.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 mappedOnce 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"
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.
Content type
Image
Digest
sha256:e42381081…
Size
49.9 MB
Last updated
over 1 year ago
docker pull jeffernz/extract-cf2tf