AWS CloudFormation vs Terraform vs AWS CDK

Comparing The Most Common IaC Tools on AWS

Cloud Digests
Geek Culture

--

As mentioned in my previous article on Infrastructure as Code (IaC), IaC is an incredibly important tool and concept to have in every tech person’s arsenal. It is the process of managing and provisioning IT infrastructure through machine-readable files like code instead of physically or manually deploying them.

You use IaC to define your infrastructure in a configuration file that contains specifications, settings and other information you need for your components. This file acts as a template and can be redeployed the same way multiple times.

IaC also comes with many benefits like increasing speed of deployments, consistency and reduction of errors, version control, cost savings and more.

When working with AWS, there are multiple IaC tools you can use, but we are going to mainly cover AWS CloudFormation, AWS Cloud Development Kit (CDK) and Terraform in this article.

AWS CloudFormation

AWS CloudFormation is the first and oldest IaC tool for AWS and was released in 2011. CloudFormation comes equipped with support for JSON and YAML template files and it is one of the most used methods of deploying IaC when utilizing AWS. As with all IaC tools, it allows you to deploy, manage, change and destroy resources in your infrastructure easily and also offers many robust features that make it very useful for everyone.

CloudFormation requires you to create or utilize an existing template, which specifies the resources you want to deploy. This template can be in JSON or YAML format. You define your resources and other attributes in the template using section headers like Parameters, Mappings, Resources and Outputs.The collection of resources created from your template is called a stack.

CloudFormation also supports resource providers, to allow the integration of third party resources and tools into your stacks, examples being Datadog and JFrog.

Some organizations that utilize AWS CloudFormation include GoDaddy, Expedia and the football club Barcelona FC. (from the AWS website)

Terraform

Terraform was introduced in 2014 and is the only tool that is not AWS-native in this list. Terraform can be used not just in AWS, but also in other cloud providers like Google Cloud Platform and Microsoft Azure. Its main selling point is the ability it gives developers to use a large ecosystem of modules and providers.

Terraform uses its own Hashicorp Configuration Language (HCL) which is basically a more human-friendly JSON, though you can also use JSON if you want to.

Terraform has a very strong community that has put together more than 1700 providers to manage almost any kind of resource and service used. This allows Terraform users to manage a wide variety of resources with just one tool, instead of having to use multiple. All available providers can be found in the Terraform Registry.

AWS CDK

AWS Cloud Development Kit (CDK) is the newest tool we have here, released in 2019. It allows developers to use typical programming languages like Python, TypeScript, Java and .NET to write template files to manage their infrastructure.

CDK is not a separate tool, but merely just another way you can utilize CloudFormation with the languages you are already familiar with. You still get to have all the CloudFormation benefits. It is generally treated by the community as a developer-friendly tool to use for their infrastructure management in AWS.

Terraform vs CloudFormation vs AWS CDK

Terraform used to have a very strong advantage over CloudFormation and CDK due to its ability to resolve inconsistencies and conflicts in state management and refresh it to automatically remedy any issues. However, CloudFormation now also has Drift Detection, which compares the current stack configuration to the one specified in the template to detect any changes or drifts.

They also differ in the way they interact with and manage your resources. Since CloudFormation is native to AWS, it will perform all intended operations on your infrastructure directly to achieve the state you declared. Since Terraform is not AWS-native and can be used across services and resources, it actually constructs a plan of API calls to AWS that creates your infrastructure.

Recently, I have heard that AWS CDK has also introduced the CDK for Terraform, which allows developers to utilize CDK to interact with Terraform. However, I am not familiar with that so if you want to find out more you can find out here.

Which To Use?

Take note that the following matches below are based on my recommendation, and they may not necessarily be the best option nor the most suitable option for your use case.

  • Simple serverless(or mostly) architectures— AWS CloudFormation
  • Only utilizing AWS for infrastructure — AWS CDK or CloudFormation
  • Utilizing multiple cloud providers or many different resources — Terraform

Other IaC Tools

Besides Terraform, AWS CloudFormation and AWS CDK, there are also many others like Ansible, Chef, Puppet, and Saltstack.

At the end, which IaC tool you choose to use should be based on what your needs and preferences are. However, I tend to always pick Terraform just because it gives me the most flexibility and future integrations should it be needed.

--

--

Cloud Digests
Geek Culture

Making Cloud Computing easy to learn and adopt for everybody, tech trained or otherwise. Simple and quick to understand content