Terraform and AWS CloudFormation are both tools that allow users to define and deploy infrastructure as code.
Here we will be comparing some key differences between Terraform and CloudFormation:
Terraform maintains a state file that keeps track of the infrastructure it is managing. This state file is used to compare the current infrastructure with the desired infrastructure defined in the configuration files. The state file is stored locally or in a remote backend, such as S3, and can be used to track the dependencies between resources.
CloudFormation, on the other hand, does not have a state file. Instead, it relies on the AWS Management Console to display the resources that have been created. This means that users must manually keep track of dependencies between resources, or use CloudFormation outputs and cross-stack references to link resources in different stacks.
There are some advantages and disadvantages to each approach to state management. The use of a state file allows Terraform to more easily track dependencies and perform operations like rolling back changes, but it also means that users must be careful to manage and secure the state file. CloudFormation’s reliance on the AWS Management Console means that users do not have to worry about managing a state file, but it can make it more difficult to track dependencies and perform certain operations.
In conclusion, Terraform is likely to be a better fit for general resources management, whereas when one has a need for a limited number of AWS based resources, or any need for AWS Lambda (Serverless) related infrastructure, we recommend going in the direction of using CloudFormation or a CloudFormation and Serverless Framework hybrid.
Both Terraform and CloudFormation are popular choices for infrastructure as code and have their own strengths and weaknesses. It’s critical to evaluate your needs and choose the tool that best fits your use case.