|What is CDK?|
|What is Terraform?|
|What is CloudFormation?|
|CDK vs Terraform vs CloudFormation|
Cloud computing has revolutionized the world of information technology. This has changed the way applications are deployed and maintained. It helped us to give a new lease of life to applications and made them highly available, scalable and efficiently architected. But with the demand boom there is a need to deploy and maintain infrastructure like a code of application as maintenance of cloud resources manually via console will be an up-hill task too complex to achieve.
Today we look more in detail about CDK vs Terraform vs CloudFormation, which are IAC (or IAAC), infrastructure as a code tools used to provision cloud services, what are their benefits and use cases.
What is CDK?
This a wrapper around AWS CloudFormation. AWS CloudFormation is an AWS managed tool to define AWS infrastructure in YAML or JASON format. They don’t have any native support for loops and functions which comes into picture while managing big infrastructures hence CDK comes to the rescue here. It is allowed to use familiar programming languages such as JAVA or Python to provision infrastructure and makes it easier to write and maintain code for the same.
What is Terraform?
Terraform an open-source infrastructure as a code tool developed by Hashicorp. It is highly accurate and mature and supports many cloud providers, not just AWS. It supports all AWS services and allows you to write code in Hashicorp developed language (HCL) which is a JSON like format to define infrastructure resources.
What is CloudFormation?
Oldest tool of IAC for AWS released in the year 2011. It comes equipped with support for JASON and YAML template files and allows to deploy, manage, change, and destroy resources in infrastructure. It lets you create or utilize an existing template which mentions what resources to be deployed. It allows integration of third-party resources and tools into stacks such as Datadog and JFrog.
CDK vs Terraform vs CloudFormation
Language and ease of use
- CDK is a CloudFormation wrapper which allows to define our resources in programming languages like JAVA or JASON.
- Terraform uses JASON like language to define resources and other data in HCL language.
- CloudFormation uses templates written in YAML or JASON formats.
- CDK is an AWS offering and limited to support AWS only.
- Terraform is a multi-cloud IAC tool and can be used with multiple cloud providers like AZURE, GCP including AWS.
- CloudFormation can be used with AWS, Azure, Google Cloud, and any other provider with a provisioning API.
- CDK code is first converted to CloudFormation templates before application and takes time as it needs to convert first.
- Terraform deploys resources using AWS SDK and works faster.
- CloudFormation covers most parts of AWS but needs some time to support new service capabilities.
- CDK – We can create reusable functions here, classes and share this code within the organization.
- Terraform has native support for modules and also has a public module registry for hosting and to use public modules.
- CloudFormation does not allow to create and reuse code as modules and it allows to use nested stacks as modules.
Cloud Resource Management
- CDK synthesizes and leverages all state management and benefits of CloudFormation.
- Terraform allows to control which resources users can create using a policy as a code tool Sentinel to apply fine grained, logic-based policies to allow/deny user actions.
- CloudFormation does not offer any control on how templates are used but you can use AWS IAM policies to allow users to use only standard templates.
- CDK – the state is stored and maintained by CloudFormation.
- Terraform stores the state of infrastructure in a state file which is stored locally by default but it can be stored remotely on a backend like S3.
- CloudFormation does not maintain a state file, at least not the one you see.
Which one to choose?
- CDK is to be used if you only want to utilize AWS for infrastructure.
- Terraform is to be used when using multiple cloud providers or many different resources.
- CloudFormation is to be used if you only want to utilize AWS for infrastructure or for simple serverless architecture.
Comparison Table: CDK vs Terraform vs CloudFormation
Below table summarizes the differences between the two:
Download the compariosn table: CDK vs Terraform vs CloudFormation
Market share: CDK (4.26%) , Terraform (0.83%) and CloudFormation (24.25%)