Terraform: Migrating from CloudFormation
HashiCorp products | HCP Terraform |
---|---|
Partner products | AWS Cloud - CloudFormation |
Maturity | Standardizing |
Use case coverage | Migration from CloudFormation templates to Terraform HCL |
Environment | PoC |
Tags | |
Publish/Updated Date | October 10, 2024 Version 1.0.0 |
Authors | Vijay Sharma |
GitHub repo | CloudFormation to Terraform migration |
Purpose of this guide
The purpose of this document is to outline patterns for migrating CloudFormation templates and AWS resources to Terraform. Mapping CloudFormation resources to Terraform requires manual effort due to the differences in design and usage between the two tools. CloudFormation is an AWS-specific UI tool, while Terraform is a CLI-based tool focused on automation.
Understand the differences
It is important for enterprises migrating from AWS CloudFormation to HCP Terraform to understand the differences between these two infrastructure as code offerings.
- Language: CloudFormation uses JSON or YAML to define infrastructure as code, while Terraform utilizes HCL (HashiCorp Configuration Language).
- State Management: Terraform maintains a state file to track infrastructure resources, enabling better management and collaboration. HCP Terraform simplifies this process by automatically handling state management, offering a secure and scalable solution for teams. AWS CloudFormation manages the state of your AWS infrastructure using a concept called stacks.
- Providers: Terraform supports a wide range of providers, not just AWS. This includes Google Cloud, Azure, and many others. This extensive provider support makes Terraform a versatile tool for multi-cloud and hybrid-cloud deployments. AWS CloudFormation is designed only to support AWS cloud infrastructure deployment.
- Modules: Terraform modules provide a way to create reusable and composable infrastructure components, promoting consistency and reducing duplication in your infrastructure code.
Please find more details on adopting Terraform in the HashiCorp Validated Design reference mentioned in the Related Resources section.
Target audience
The primary audience for this document is:
- Cloud architects and platform teams
- DevOps and infrastructure engineers
Prerequisites
- Review Terraform Solution Design Guide and Operating Guides.
- An active AWS account.
- A GitHub, BitBucket, or other source repository.
- An HCP Terraform account.
Overview
Migrating from AWS CloudFormation to HCP Terraform involves a systematic approach to convert existing infrastructure as code (IaC) setups. The goal is to maintain or improve the current infrastructure state while leveraging the capabilities of Terraform for enhanced flexibility, provider support, and ecosystem integration.
This approach can be divided into three primary use cases.
- Migrating existing CloudFormation templates into Terraform resources: This involves translating CloudFormation templates directly into Terraform configurations.
- Executing complex CloudFormation runs using Terraform: This can be achieved by utilizing Terraform to run existing CloudFormation templates, which is especially useful for complex scenarios where existing CloudFormation scripts need to be maintained initially.
- Migrating existing resources created Using CloudFormation into HCP Terraform using the Terraform import workflow: This method involves importing existing infrastructure resources into the Terraform state, allowing for seamless management and further modification using Terraform.