Terraform vs. CloudFormation – Which is the Better Infrastructure Provisioning Tool?

Author

SriSainath Adusumilli

Software Engineer

Published May 29 2020

Since its inception almost a decade ago, Infrastructure as Code (IaC) has transformed the way IT infrastructure is set up and managed. Thanks to the fast-paced evolution of the practice, IaC is now more accessible through a comprehensive range of tools available for automating the entire provisioning process. Terraform, Ansible, Chef, Puppet, and SaltStack are some popular IaC tools that are being used extensively these days.

When infrastructure is defined as code, you are able to use a wide variety of software engineering practices to dramatically improve the software delivery process. According to a white paper published on puppet.com, organizations that use DevOps practices, such as IaC, can deploy 200 times more frequently and recover from failures 24 times faster.

Configuration management and infrastructure provisioning tools are used in the DevOps lifecycle to accelerate software development or reduce the time taken to propagate a new feature to production. Chef/Puppet are popular configuration management tools and Terraform/CloudFormation are popular infrastructure provisioning tools.

The infrastructure provisioning tools can help in provisioning your application, dependencies, and the underlying cloud infrastructure. The number of companies that use Terraform to manage infrastructure is almost double when compared to the number of companies that use CloudFormation to manage their infrastructure/cloud resources. (Source: hgdata.com)

Choosing a Provisioning Tool on AWS: Terraform vs. CloudFormation

While there are many tools that are available to achieve programmable infrastructure for all sizes of organizations, let’s discuss and compare Terraform and CloudFormation that are available for AWS.

CloudFormation

It is an AWS-specific tool that can be used to provide all types of AWS services, such as S3 buckets, EC2 instances, RDS databases, and load balancer. It allows you to describe the resources that are needed in a simple form of code (JSON) using uncomplicated templates that are easy to use. You can write the templates from scratch or just drag and drop the resources that can deploy/manage in a Graphical User Interface (GUI).

Key Points to Consider While Using CloudFormation

The section below discusses the key features of using CloudFormation:

  • CloudFormation can only be used to orchestrate or manage AWS resources. If you need to integrate any third-party resource that is not provided by AWS, then it's best to incorporate another tool.
  • Any new service provided by AWS by default comes with relevant resources that are required to deploy using CloudFormation.
  • You can manage different stages of your deployment using CloudFormation. For example, if you have deployed a version of your application from scratch and the next version is ready, the deployed version can be updated with the new parameters or options.
  • CloudFormation is seamlessly integrated with the rest of AWS services, so you don’t have to make any changes/custom automation for things to work together, such as alerts, logs, notifications, etc.
  • You cannot make a ‘what-if’ scenario or plan a dry-run on your infrastructure using CloudFormation.

 CloudFormation User Interface

AWS CloudFormation Designer offers a template diagram with icons indicating the AWS resources and arrow signs that define the relationship between the resources. You can create and modify templates using the interface and also alter template details with the help of the inbuilt JSON text editor if needed.

AWS Cloud Formation Sample UI

Terraform

Terraform has a wide variety of resources that can be provisioned using AWS APIs. It is an open-source tool created by HashiCorp that has developed many infrastructure tools over the past years, all of which are easy to use and capable of interacting with many platforms.

Key Points to Consider While Using Terraform

The section below discusses the key features of Terraform:

  • Terraform is a cross-platform tool, i.e., it is not only designed to work with AWS but can also interact with other cloud solution providers, such as Azure, GCP, OpenStack, VMware, and more.
  • Terraform can interact with many other types of services that are not related to any cloud provider (like Consul, GitHub, Grafana, and Vault) and can become an integral part of your ecosystem.
  • Terraform uses a high-level configuration language that is very easy to write and understand, which makes writing Terraform (.tf) files easier. It supports an alternative syntax that is compatible with JSON (.tf.json).
  • You can’t immediately use Terraform to orchestrate any newly released AWS service/resource since writing code is a time-consuming process and the developers may take longer while contributing to an open-source project.
  • You can make a dry-run/plan on your Infrastructure using Terraform.
  • You can provide the architecture for a web application on Google Compute Engine Terraform with a few commands.

Architecture Diagram for a Simple Web App in GCP Compute Engine

 

Enterprise Support: Terraform vs. CloudFormation

Both Terraform and CloudFormation provide support services for the enterprises. AWS (CloudFormation) comes with a certain level of support and it can include premium support with professional services (based on your account contract). Terraform has an enterprise support plan/option that offers 24/7 support, auditing, and MFA (Multi-factor Authentication) for certain operations.

 In a nutshell, here is the comparative analysis of Terraform and CloudFormation:

Comparative Analysis of Terraform and CloudFormation

There is no single tool that has all the options that you need. Both CloudFormation and Terraform have their respective advantages and limitations. In our projects, we often opt for Terraform first because of its planning feature and non-AWS components in the project working environment. It is also more pleasant to write Terraform templates than bickering pure JSON with CloudFormation. But if all your applications and environments are on AWS, then Terraform cannot provide you the AWS support you need. In such a case, CloudFormation would be a better choice.