Terraform vs CloudFormation

How Terraform and CloudFormation works?

Both Terraform and CloudFormation work in same way. Define the target state of the cloud resource in the template ( CloudFormation) or Configuration file (terraform ), use these tools to evaluate configurations and calculate the changes needed in the existing state to reach the final state and then allow the user to verify the changes before executing it finally. Now let us see the difference between these tools

Terraform vs CloudFormation

1. Existing Resources

If you want to slowly transition infrastructure to Terraform , you can easily do it with the Terraform “import” feature. Also, you can query the attributes from your existing resources in Terraform. But it is not possible to manage or integrate existing resources with CloudFormation.

2. Modularization

Modularizing your infrastructure components will make our life easy, we don’t have to manage a single blueprint which contains configs for all the components under your AWS account. With modularization, each project can have their own Git repo containing their infrastructure code, which is easy to maintain and less prone to errors. Also, the accidental deletions can affect only limited resources.
Both terraform and CloudFormation supports modularizing your infrastructure blueprints.

3. Rolling Updates

When using an update policy, CloudFormation will perform a rolling update with rollback option in case of a failure. Terraform does not support rolling updates for Auto Scaling Groups out-of-the-box.

4. Learning curve

CloudFormation templates are JSON (or YAML) formatted. It’s been designed to be consumed and produced by computers — not humans. Writing and reading json templates is a bit difficult.
The syntax of Terraform configurations is called HashiCorp Configuration Language (HCL). It is meant to strike a balance between human-readable and editable as well as being machine-friendly. For machine-friendliness, Terraform can also read JSON configs.

Summary :

If you have resources spread over multiple providers ( AWS, GCP , GitHub ) you should definitely go with Terraform. If its AWS based, you can go with either Terraform or CloudFormation, but there is a steep learning curve for CloudFormation.

 
Author: , 0000-00-00