What are the differences? Which tool is the best for your needs?
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. 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, 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 as well to the table - here is your update π.
Feature | ||||
---|---|---|---|---|
Supported AWS Resources | 500+ | 500+ | 400+ | 400+ |
Integration of new features after announcement | β After announcement of a new feature there is always a delay until it is integrated into CDK, but you can use Escape Hatches to workaround these missing features. | β 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 to cover new features. | β After announcement of a new feature there is always a delay until it is integrated into Pulumi. |
License and Support | β Open-source with support from AWS. | β Free with support from AWS and large community. | β Open-source with support from Hashicorp and large community. | β Open-source with support from Pulimi and large community. |
Third Party | β CDK supports third-party resources. | β CloudFormation supports third-Party vendors to create resource providers. | β Terraform supports third-party providers and provisioners. | β Pulumi supports third-party providers. |
CLI | β 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. | β CloudFormation has a CLI that enables you to develop and test AWS and third-party resources and register them for use in AWS CloudFormation. | β Terraform has a single command-line application. | β Pulumi has a single command-line application. |
Language | β Supports multiple programming languages Typescript, Javascript, Python, Java, and C# | β JSON / YAML - YAML is easier to read than JSON but it forces you to have multiple nested scopes. | β HCL is human readable as well as machine-friendly. | β Supports multiple programming languages Typescript, Javascript, Python, Go - in preview, and C# - in preview |
Modularization | β CDK supports modules to create a reproducible infrastructure. | β Nested stacks and cross-stack references can be used to achieve modularization. | β Terraform modules help to create a reproducible infrastructure. | β Pulumi modules help to create a reproducible infrastructure. |
State Management | β Deploys CloudFormation Stacks to manage its state. | β Uses Stacks to manage its state. | β 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. | β Pulumi saves the state (called checkpoint) locally but it is possible to save the state in Pulumi service backend or S3. |
Configuration | β Supports Environment Variables, CloudFormation Parameters or you can get values from SSM. | β Supports up to 60 Parameters. Import values from output of another stack or import from SSM. | β Data sources allow data to be fetched or computed for use elsewhere in Terraform configuration. | β 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 | β 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. | β Change Sets help you to verify changes before you apply them on your stack. | β terraform plan creates a detailed execution plan before applying your changes. | β pulumi preview previews your changes explicitly before deploying. |
Error handling and rollback | β AutoRollbackConfig helps you to configure the behavior of automatically rolling back for a given Deployment Group. | β CloudFormation automatically rolls back to the last working state. | β | β Currently there is no rollback functionality in Pulumi but there is an open RFC to implement this functionality. |
Import Existing Resources | β Currently its not possible to import resources into CDK, but there is an open RFC to implement this functionality. Additional information - there are workarounds how to use existing resources in CDK. | β It is possible to import resources into CloudFormation but only for a few resources. | β It is possible to import resources into terraform but it does not generate configuration. | β 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 | β | β | β You can implement rolling updates for Auto-Scaling Groups using the create before destroy lifecycle policy. | β You can implement rolling updates for Auto-Scaling Groups using the createBeforeDestroy lifecycle policy. |
External waiting conditions | β You can use CfnWaitCondition to coordinate resource creation with configuration actions that are external to the stack creation. | β You can use WaitCondition to coordinate resource creation with configuration actions that are external to the stack creation. | β You can use null_resource to coordinate resource creation with configuration actions that are external to native Terraform resources. | β 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 | β CDK has a plugin for Visual Studio Code which visualizes dependencies or you can use the cli. | β You can use the AWS CloudFormation Designer to view CloudFormation templates. | β You can use the terraform graph command to generate a visual representation of either a configuration or execution plan. | β You can use pulumi stack graph to export a stackβs dependency graph to a file. |
Multi-Cloud Management | β | β | β | β |
Top comments (0)