CloudFormation vs. Terraform
Tags: aws, terraform, iac, cdk
Published: 2021-01-26 12:36:17

---
title: CloudFormation vs. Terraform
published: true
date: 2020-02-28 09:15:00 UTC
tags: #aws #terraform #iac #cdk
canonical_url: https://globaldatanet.com/blog/cloudformation-vs-terraform
---

What are the differences? Which tool is the best for your needs?


![CDK vs. CloudFormation vs. Terraform vs. Pulumi](https://dev-to-uploads.s3.amazonaws.com/i/94wlczsd7nzaxm20hdih.png)

When you want to implement infrastructure as code, you always come to the question if you should use CloudFormation or HashiCorp's open-source tool [Terraform](https://www.terraform.io/). Both have their advantages and disadvantages. I compared both in the following table to help you decide which tool is best suited for your needs. 

### Update 
Since there was a lot of feedback that you would like to have a comparison including the [AWS CDK](https://github.com/aws/aws-cdk), I expanded the table by one column for the AWS CDK. I hope the table will help you to make the decision for the right tool for you.

⁉️ Some people asked me to add [Pulumi](https://www.pulumi.com/) as well to the table - here is your update 🚀. 
<br>

| Feature                  |  ![AWS CDK](https://dev-to-uploads.s3.amazonaws.com/i/rl650493xfemf9z83mlc.png)|![CloudFormation](https://dev-to-uploads.s3.amazonaws.com/i/e9njd9a4153jvdglsybv.png) | ![Terraform](https://dev-to-uploads.s3.amazonaws.com/i/z48qxsa41xxbo5u5iqtu.png)|  ![Pulumi](https://dev-to-uploads.s3.amazonaws.com/i/jqzkimhdbk0uce3muoyp.png) | 
|-------------------------|:-----:|:-----:|:-----:|:-----:|
| Supported AWS Resources | 500+ |500+ | 400+ |400+ |
| Integration of new features after announcement|➖ </br>After announcement of a new feature there is always a delay until it is integrated into CDK, but you can use [Escape Hatches](https://docs.aws.amazon.com/cdk/latest/guide/cfn_layer.html) to workaround these missing features. |➖ </br> After announcement of a new feature there is always a delay until it is integrated into CloudFormation, but as a workaround you can develop **custom resources** to cover new features.|➖ After announcement of a new feature there is always a delay until it is integrated into Terraform, but as a workaround you can use [terraform-aws-anything](https://github.com/antonbabenko/terraform-aws-anything) to cover new features.  |➖ After announcement of a new feature there is always a delay until it is integrated into Pulumi. 
| License and Support | ➖ </br> Open-source with support from AWS.|➖ </br> Free with support from AWS and large community. | ➖</br>  Open-source with support from Hashicorp and large community. |➖</br>  Open-source with support from Pulimi and large community. |
| Third Party | ✅  </br> CDK supports third-party resources. |✅  </br> CloudFormation supports third-Party vendors to create resource providers. | ✅ </br>  Terraform supports third-party providers and provisioners. |✅ </br>  Pulumi supports third-party providers. |
| CLI |✅ </br> **CDK CLI** enables you to list the stacks defined in your CDK app, synthesize the stacks into CloudFormation templates, determine the differences between running stack instances and the stacks defined in your CDK code and deploy stacks to any public AWS Region.  |✅  </br> CloudFormation has a CLI that enables you to develop and test AWS and third-party resources and register them for use in AWS CloudFormation.| ✅  </br> Terraform has a single command-line application.  |✅  </br> Pulumi has a single command-line application.| 
| Language| ✅ </br> Supports multiple programming languages **Typescript**, **Javascript**, **Python**, **Java**, and **C#**|➖ </br> **JSON** / **YAML** - YAML is easier to read than JSON but it forces you to have multiple nested scopes. | ✅ </br> **HCL** is human readable as well as machine-friendly. | ✅ </br> Supports multiple programming languages **Typescript**, **Javascript**, **Python**, **Go - in preview**, and **C# - in preview**|
| Modularization | ✅ </br> CDK supports modules to create a reproducible infrastructure. |➖ </br> **Nested stacks** and cross-stack references can be used to achieve modularization. | ✅ </br> Terraform modules help to create a reproducible infrastructure. | ✅ </br> Pulumi modules help to create a reproducible infrastructure.|
| State Management |✅ </br> Deploys CloudFormation Stacks to manage its state.| ✅ </br> Uses Stacks to manage its state.  | ✅ </br> By default saves the state locally but it is possible to save the state in Terraform Cloud, S3 or DynamoDB with the remote state feature.|✅ </br> Pulumi saves the state (called **checkpoint**) locally but it is possible to save the state in Pulumi service backend or S3.|
|Configuration|✅ </br> Supports Environment Variables, CloudFormation Parameters or you can get values from SSM. |✅ </br> Supports up to 60 Parameters. Import values from output of another stack or import from SSM. |✅ </br> Data sources allow data to be fetched or computed for use elsewhere in Terraform configuration. |✅ </br> Pulumi offers  a **Config** object with various getters and setters for retrieving values, in addition they have Data sources that allow  to grep, for example an AMI or an AZ from AWS.| 
| Change management |✅ </br>  **cdk diff** compares the desired state against the stack but it doesn't look at the deployed resources until you deploy. You only find out about discrepancies between the stack and deployed resources at deployment time.| ✅ </br> **Change Sets** help you to verify changes before you apply them on your stack.| ✅ </br> **terraform plan** creates a detailed execution plan before applying your changes. |✅ </br> **pulumi preview** previews your changes explicitly before deploying.|
| Error handling and rollback |✅ </br>  AutoRollbackConfig helps you to configure the behavior of automatically rolling back for a given Deployment Group.| ✅ </br> CloudFormation automatically rolls back to the last working state. | ❌ | ❌ </br>Currently there is no rollback functionality in Pulumi but there is an [open RFC](https://github.com/pulumi/pulumi/issues/96) to implement this functionality.|
| Import Existing Resources | ❌ </br> Currently its not possible to import resources into CDK, but there is an [open RFC](https://github.com/aws/aws-cdk-rfcs/issues/84) to implement this functionality. Additional information - there are workarounds how to use [existing resources](https://garbe.io/blog/2019/09/20/hey-cdk-how-to-use-existing-resources/) in CDK. | ➖ </br> It is possible to import resources into CloudFormation but only for a few resources.  | ➖</br> It is possible to import resources into terraform but it does not generate configuration. |✅</br>Pulumi offers an **import** resource option to request that a resource defined in your Pulumi program adopts an existing resource in the cloud provider instead of creating a new one. |
|Rolling updates for Auto-Scaling Groups  | ✅ |✅ | ✅ </br> You can implement rolling updates for Auto-Scaling Groups  using the **create before destroy** lifecycle policy. | ✅ </br> You can implement rolling updates for Auto-Scaling Groups  using the **createBeforeDestroy** lifecycle policy. |
|External waiting conditions | ✅ </br> You can use **CfnWaitCondition** to coordinate resource creation with configuration actions that are external to the stack creation.|✅ </br> You can use **WaitCondition** to coordinate resource creation with configuration actions that are external to the stack creation. | ✅ </br> You can use [null_resource](https://www.terraform.io/docs/providers/null/resource.html) to coordinate resource creation with configuration actions that are external to native Terraform resources.  |✅ </br> You pass a **customTimeouts** object as part of resource options to coordinate resource creation with configuration actions that are external to the resource.|
|Drift Detection |✅ |✅ | ✅ |✅ |
|Visualization of dependencies |✅ </br> CDK has a plugin for Visual Studio Code which visualizes dependencies or you can use the [cli](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md#visualizing-dependencies-in-a-cloudformation-template).|✅ </br> You can use the AWS CloudFormation Designer to view CloudFormation templates.| ✅ </br> You can use the **terraform graph** command to generate a visual representation of either a configuration or execution plan.  |✅ </br> You can use **pulumi stack graph** to export a stack’s dependency graph to a file.|
|Multi-Cloud Management |❌ |❌ | ✅ |✅ |