Terraform vs CloudFormation: Key Differences

Hello. In this tutorial, we will explain a popular topic among DevOps culture. We will discuss the key differences between Terraform vs CloudFormation tools.

1. Introduction

DevOps these days is gaining popularity these days due to the industry’s interest in automation tools. Here in this tutorial, we will explore the key differences between Terraform and Ansible.

1.1 Terraform

Terraform is an open-source tool developed by HashiCorp for building, changing, and versioning the infrastructure safely and efficiently. It is used to manage the infrastructure of the popular cloud service providers and custom in-house solutions. It helps manage both low-level (Compute, Storage, Networking, etc.) and high-level components (such as SaaS, DNS, etc.) Terraform deployment automation is divided into different sections i.e. –

  • IaaC – IaaC is popularly known as the Infrastructure as a Code wherein the infrastructure is described using a high-level configuration syntax. This allows a blueprint of the infrastructure which can be deployed, versioned, and shared for re-use
  • Execution Plans – Terraform has a planning step where it generates an execution plan. The execution plan tells the administrator what Terraform will do once applied and helps to avoid any surprises when it creates the infrastructure
  • Resource Graph – Terraform builds a graph of all the resources and parallelizes the creation and modification of non-dependent resources. This offers insights into learning the dependencies in their infrastructure
  • Change Automation – Terraform allows to apply of complex changesets to the infrastructure with minimal human intervention

1.1.1 Configuration language

Terraform has its configuration language designed to meet the infrastructure automation requirements. The main purpose of this language is to declare resources and a group of resources (gathered into a module) represents a larger unit of configuration. Language syntax consists of a few elements i.e. – Blocks, Arguments, and Expressions.

  • Blocks – Containers for other contents and represents the object configuration
  • Arguments – Assign a value to the name and appear within the blocks
  • Expressions – Represents a single value, referenced value, or combination of other values

1.1.2 Steps

To create the infrastructure via the Terraform scripts following commands need to be executed in a sequence. However, details and actions may differ between workflows.

  • terraform init – Initializing the new or existing terraform configuration
  • terraform plan – Generate the execution plan from the resources specified in the file
  • terraform apply – Create the infrastructure from the resources specified in the file
  • terraform destroy – Destroy the created infrastructure
terraform vs cloudformation - terraform workflow
Fig. 1: Terraform workflow

1.2 AWS Cloudformation

Amazon Cloudformation is a service responsible to create AWS resources and provision them in a well-ordered fashion.

  • It is known as infrastructure as a code
  • It is different from Elastic Beanstalk as the latter is focused on deploying applications on elastic compute
  • It uses JSON or YAML template files
  • Similar to Terraform
  • It consists of:
    • Stacks – Tells the entire environment described by the template and created, updated, and deleted as of a single unit
    • Changesets – Tells the summary of proposed changes to the stack which allows seeing how the changes will impact the existing resources before implementing them
  • Integrates with other development and CI/CD tools

1.2.1 Anatomy of a Template

A cloud formation template file consists of three main sections i.e. Parameters, Resources, and Outputs.

  • The parameter is responsible to define the user-defined values in the template. Using parameters makes the template reusable. When a user creates a new stack for the template, the cloud formation interface will provide fields for them to fill out the parameter values
  • The resource is the main recipe of the template. It defines which AWS resources should be created when this template is run through cloud formation
  • The output is where we define the information that should be provided to the user after the resources are created

1.2.2 Pricing

  • Cloudformation is free of cost for the users
  • Users only pay for the provisioned AWS resources created using the cloud formation template

2. Terraform vs CloudFormation: Key Differences

The below table lists the Terraform and CloudFormation differences:

AWS CloudformationTerraform
Cloudformation cover AWSTerraform cover AWS and other cloud providers
Managed service offered by AWS for freeIt is an opensource project
JSON and YAML based templates are supportedHas its own template
Does not use modulesOffers code reuse by supporting modules
Manages state within an out-of-box managed serviceStores its state on the disk by default. Offers a remote state
Offers changesets to verify the implemented changesProvides a named plan command for a detailed overview
Supports rolling update of autoscaling groups, including a rollback in case of failureNo support for rolling updates of autoscaling groups

2.1 Which one to choose?

Deciding between Cloudformation or Terraform is tough to make when it comes to infrastructure needs. Both of them are flexible tools and offer good state management and automated logging. If you’re mainly working with AWS resources, Cloudformation might work best for you. But if your infrastructure relies on third-party resources, Terraform is a better option.

That is all for this tutorial and I hope the article served you with whatever you were looking for. Happy Learning and do not forget to share!

3. Summary

In this tutorial, we saw the differences between the Terraform vs the AWS CloudFormation tools. Terraform is used to manage the infrastructure of the cloud service providers. The CloudFormation is a service responsible to create AWS resources.


An experience full-stack engineer well versed with Core Java, Spring/Springboot, MVC, Security, AOP, Frontend (Angular & React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Back to top button