---
title: "Which Tool? Terraform vs. Cloudformation in the Fight for AWS"
description: "Learn which tool, Terraform vs. Cloudformation is right for infrastructure as configuration with AWS in this ATA Learning tutorial!"
canonical: "https://adamtheautomator.com/terraform-vs-cloudformation/"
---

# Which Tool? Terraform vs. Cloudformation in the Fight for AWS

> Learn which tool, Terraform vs. Cloudformation is right for infrastructure as configuration with AWS in this ATA Learning tutorial!

Source: https://adamtheautomator.com/terraform-vs-cloudformation/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Which Tool? Terraform vs. Cloudformation in the Fight for AWS](https://adamtheautomator.com/wp-content/uploads/2022/08/Which-Tool-Terraform-vs-Cloudformation-in-the-Fight-for-AWS.jpg)

# Which Tool? Terraform vs. Cloudformation in the Fight for AWS

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)23 August 20226 min. read

Categories: [DevOps](/category/devops/)

Tags:[AWS](/tag/aws/)[AWS CloudFormation](/tag/aws-cloudformation/)[Terraform](/tag/terraform/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Terraform vs. CloudFormation](#terraform-vs-cloudformation)
*   [Launching AWS Services Using Terraform](#launching-aws-services-using-terraform)
*   [Launching AWS Services Using CloudFormation](#launching-aws-services-using-cloudformation)
*   [Conclusion](#conclusion)

Nowadays, setting a cloud using [Infrastructure as Code (IaC)](https://en.wikipedia.org/wiki/Infrastructure_as_code) is common, and multiple IaC tools are available for infrastructure provisioning. But which one to choose? CloudFormation and [Terraform](https://www.terraform.io/) are two of the big names in the IaC space. See how the Terraform vs. Cloudformation debate plays out.

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

This tutorial will show you, rather than fight, how these tool uses their way to accomplish the provisioning of various Cloud services.

Stay tuned so you can decide which tool works best for your infrastructure!

## Prerequisites

This tutorial will be a step-by-step demonstration. If you’d like to follow along, ensure you have the following in place:

*   An [Amazon Web Service (AWS) account](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).
*   A code editor – Even though you can use any text editor to work with Terraform configuration files, consider using [Visual Studio (VS) Code](https://code.visualstudio.com/) as it understands the HCL Terraform language well.
*   An Ubuntu machine – This tutorial uses Ubuntu 20.04 LTS, but any operating system with Terraform works.
*   [Terraform](https://www.terraform.io/docs/enterprise/install/index.html) installed on your Ubuntu machine – This tutorial uses [Terraform](https://adamtheautomator.com/install-terraform/) v1.1.5.

Related:[How to Install Terraform on Linux and Windows](https://adamtheautomator.com/install-terraform/)

## Terraform vs. CloudFormation

A fight between Terraform and CloudFormation? What’s the difference between the two anyway?

*   Terraform is a tool for building, versioning, and updating the infrastructure.
*   AWS CloudFormation is a service that allows you to set up and manage your AWS resources and applications that run in AWS.

But read on to understand the differences between the two better, starting with Terraform.

## Launching AWS Services Using Terraform

Terraform allows you to build, change, and version infrastructure via a configuration in .tf format or .tf.json or .tfvars format. Terraform configuration files, placed inside the [Terraform modules](https://www.terraform.io/language/modules/syntax), are written in a tree-like structure to ease the overall code understanding. A Terraform module is a place for multiple resources that are used together.

Since you’ll be using the Terraform modules to create AWS EC2 instance, AWS S3 bucket, and AWS RDS in AWS Cloud, you’ll first have to build a Terraform configuration. This configuration defines all services that Terraform will build.

To build a Terraform configuration:

1\. Log in to the Ubuntu machine with your favorite SSH client.

Related:[How to Set up the SSH Chrome Extension](https://adamtheautomator.com/ssh-chrome-extension/)

2\. Next, run the commands below to create a working directory called ~/terraform-aws-services-demo_._ This folder will contain all the configuration files you’ll be working on in this tutorial.

```bash
mkdir ~/terraform-aws-services-demo
cd ~/terraform-aws-services-demo
```

3\. Create a file called _main.tf_ in your preferred code editor, and add the following configuration to the _main.tf_ file, and save the changes.

> _The Terraform configuration below is specific to this tutorial and its AWS subscription. Make sure to customize the configuration as needed or if you encounter errors._

Terraform execution and configuration files are written in IaC language, which comes under High-level language that is more human-readable.

The configuration below creates instances for the AWS EC2, S3, and RDS services module.

```powershell
resource "aws_instance" "my-machine" {
   ami = var.ami
   instance_type = var.instance_type
   tags = {
      Name = "my-machine"
           }
}
resource "aws_s3_bucket" "b" {
  bucket = "my-s3-infra-bucket"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

resource "aws_db_instance" "default" {
# Allocating the storage for the database instance.
  allocated_storage    = 10
# Declaring the database engine and engine_version
  engine               = var.engine
  engine_version       = var.engine_version
# Declaring the instance class
  instance_class       = var.instance_class
  name                 = var.name
# User to connect the database instance 
  username             = var.username
# Password to connect the database instance 
  password             = var.password
  parameter_group_name = var.parameter_group_name
}
```

4\. Now, create another file called _vars.tf_, and populate the code below.

The _vars.tf_ file is a [Terraform variables file](https://www.terraform.io/docs/language/values/variables.html) that contains all variables the configuration file references.

```powershell
# Creating a Variable for ami
variable "ami" {       
  type = string
}
 
# Creating a Variable for instance_type
variable "instance_type" {    
  type = string
}
variable "engine" {}
variable "engine_version" {}     
variable "instance_class" {}
variable "name"  {}       
variable "username" {}  
variable "password" {} 
variable "parameter_group_name" {}
```

5\. Create one more file named _terraform.tfvars_, and add the code below to the file.

The code below defines the values that replace the variable references in the configuration file (_main.tf_).

When Terraform creates the AWS RDS instance, the instance will be a MySQL v5.7 database running on a t3.micro engine. With an admin username of user1 with a password of password

```bash
  engine               = "mysql"
  engine_version       = "5.7"
  instance_class       = "db.t3.micro"
  name                 = "mydb"
  username             = "user1"
  password             = "password"
  parameter_group_name = "default.mysql5.7"
```

6\. Create one more file called _provider.tf_, and populate the following code to define the [AWS provider](https://registry.terraform.io/providers/hashicorp/aws/latest/docs).

> _This tutorial creates resources in the us-east-1 region. But a list of_ [_regions that AWS support_](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) _is also available._

```bash
provider "aws" {
   region = "us-east-2"
 }
```

Related:[Getting Started with the Terraform AWS Provider](https://adamtheautomator.com/terraform-aws/)

7\. Now, run the terraform init command below to initialize the provider and plugins.

```powershell
terraform init
```

![Initializing the provider and plugins](https://adamtheautomator.com/wp-content/uploads/2022/08/image-298.png)

Initializing the provider and plugins

8\. Once initialized, run the below terraform plan command to view what resources need to be created or deleted. Think of this command as a dry-run.

Another factor that makes Terraform powerful is that Terraform provides you with in-depth details of the execution plan. Such as what Terraform will provision before deploying the actual code and resources to create.

```powershell
terraform plan
```

The output below shows the plan’s summary where there’s nothing to change and destroy/delete, but there ate six (6) resources to add/create.

![Viewing what resources need to be created or deleted](https://adamtheautomator.com/wp-content/uploads/2022/08/image-299.png)

Viewing what resources need to be created or deleted

9\. Lastly, run the following terraform apply command to apply the plans laid out in step eight.

```powershell
terraform apply
```

The output below shows that the AWS resources creation has been completed for AWS EC2, S3, and RDS services module.

But suppose you don’t have any experience writing Terraform modules using HCL Language. In that case, CloudFormation is your best choice. CloudFormation allows you to generate the CloudFormation templates using its [designer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/working-with-templates-cfn-designer.html), where you drop the resource types as diagrams.

![Creating or deleting the AWS resources as specified in the Terraform plan](https://adamtheautomator.com/wp-content/uploads/2022/08/image-300.png)

Creating or deleting the AWS resources as specified in the Terraform plan

## Launching AWS Services Using CloudFormation

You’ve seen how to deploy AWS EC2, AWS S3 buckets, and RDS services using Terraform. But this time, you’ll create a YAML formatted template file to create a [CloudFormation stack](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacks.html) and launch AWS EC2, RDS, and S3 buckets.

Unlike Terraform, CloudFormation uses templates (in JSON or YAML format) instead of modules to describe AWS resources to create. These resources can be but are not limited to AWS EC2 instances or AWS RDS DB instances. CloudFormation then provisions the resources using the stack.

To create and deploy a YAML formatted template using Cloud Formation stack:

1\. Create a file named _CloudFormation.yml_ and add the code below to the file, which creates three resources as follows:

*   AWS EC2 instance of t2.nano type with key1 as key.
    
*   AWS RDS instance of type db.t3.micro with Postgres as the engine.
    
*   AWS S3 bucket (named ata-this-bucket).
    

```powershell
# Creating Cloudformation template
AWSTemplateFormatVersion: 2010-09-09
Description: 'AWS CloudFormation Ec2'
# Resources here mean AWS services.
Resources:
  WebInstance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.nano
      ImageId: ami-08d4ac5b634553e16
      KeyName: key1

  WebAppDatabase:
# Defining the RDS Instance
    Type: AWS::RDS::DBInstance
    Properties:
      DBInstanceIdentifier: atadb
      AllocatedStorage: "5"
      DBInstanceClass: db.t3.micro
      Engine: postgres
      MasterUsername: DBUsername
      MasterUserPassword: DBPassword

# Defining the AWS S3 bucket
  S3Bucket:
    Type: AWS::S3::Bucket
    Description: Creating Amazon S3 bucket from CloudFormation
    Properties:
      BucketName: ata-this-bucket
```

2\. Next, switch to the AWS Management Console, and look for and access CloudFormation services, as shown below.

![Accessing CloudFormation services in the AWS Management console](https://adamtheautomator.com/wp-content/uploads/2022/08/image-301.png)

Accessing CloudFormation services in the AWS Management console

3\. On the CloudFormation page, click Create Stack (right-most) to initiate creating a stack (step four).

![Initiating creating a stack](https://adamtheautomator.com/wp-content/uploads/2022/08/image-302.png)

Initiating creating a stack

4\. Now, configure the new stack with the following:

*   Select the **Template is ready** option under the **Prepare template** section since you already have a template (_CloudFormation.yml_).
    
*   Choose the **Upload a template file** option, and click on **Choose file** to locate the template file you created in step one (_CloudFormation.yml_).
    
*   Click **Next** to specify the stack details.
    

![Specifying the stack template](https://adamtheautomator.com/wp-content/uploads/2022/08/image-303.png)

Specifying the stack template

5\. Specify a unique Stack name (ATAstack), and click on the Next button. The stack will be created and launch all the resources defined in the template file.

![Specifying a stack name](https://adamtheautomator.com/wp-content/uploads/2022/08/image-304.png)

Specifying a stack name

As you can see below, the resources (AWS EC2, AWS RDS, and AWS S3) are provisioned successfully.

![Checking the CloudFormation stack](https://adamtheautomator.com/wp-content/uploads/2022/08/image-305.png)

Checking the CloudFormation stack

6\. Finally, verify all the provisioned components (S3 bucket, AWS EC2 instance, and AWS DB instance).

In the following screenshots, you can verify that you’ve successfully created instances like you would with Terraform but through AWS Management Console.

Even though Terraform works with various public clouds such as oracle, Azure, and Google Cloud, CloudFormation is superficially used to manage AWS services. So if you’re working entirely with AWS services, there is no doubt that CloudFormation suits you.

![Verifying the AWS S3 bucket in the AWS Management Console](https://adamtheautomator.com/wp-content/uploads/2022/08/image-306.png)

Verifying the AWS S3 bucket in the AWS Management Console

![Verifying the AWS EC2 instance in the AWS Management Console](https://adamtheautomator.com/wp-content/uploads/2022/08/image-307.png)

Verifying the AWS EC2 instance in the AWS Management Console

Related:[Verifying the AWS EC2 Instance and Local Backend](https://adamtheautomator.com/terraform-backend/#Verifying_the_AWS_EC2_Instance_and_Local_backend)

![Verifying the AWS DB instance in the AWS Management Console](https://adamtheautomator.com/wp-content/uploads/2022/08/image-308.png)

Verifying the AWS DB instance in the AWS Management Console

Related:[Verifying the AWS RDS Was Created with Terraform](https://adamtheautomator.com/terraform-and-aws-rds/)

> _Both CloudFormation and Terraform are flexible for provisioning resources in AWS resources when using third-party tools such as Postgres or Docker. But it’s worth noting that Terraform is much more advanced and compatible._

## Conclusion

Terraform and CloudFormation are both great tools. They set out to perform and achieve a job brilliantly. And in this tutorial, you’ve seen that both tools let you handle provisions of Cloud services depending on your expertise or what fits your needs.

Each tool aims to achieve different things and never completely matches the other’s feature set. This focus is a good thing! So why not get started with Terraform and CloudFormation for your IaC journey?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fterraform-vs-cloudformation%2F&text=Which%20Tool%3F%20Terraform%20vs.%20Cloudformation%20in%20the%20Fight%20for%20AWS)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fterraform-vs-cloudformation%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fterraform-vs-cloudformation%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/07/A-Definitive-Guide-to-Leveraging-the-AWS-Terraform-IAM-Role.jpg)

### [A Definitive Guide to Leveraging the AWS Terraform IAM Role](/terraform-iam-role/)

Discover this definitive guide to the AWS Terraform IAM role and take your devops game to the next level in this ATA Learning tutorial.

![](https://adamtheautomator.com/wp-content/uploads/2022/02/Learn-How-to-Deploy-Terraform-Autoscaling-Groups-Quickly.jpg)

### [Learn How to Deploy Terraform Autoscaling Groups Quickly](/terraform-autoscaling-group/)

Learn how to achieve zero downtime with your AWS EC2 instances by deploying Terraform autoscaling groups quickly in this step-by-step tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2022/07/Move-Development-to-the-Cloud-with-the-AWS-Cloud9-IDE.jpg)

### [Simplify Development with AWS Cloud9: Your Cloud-Based IDE](/aws-cloud9/)

Simplify your development workflow, boost productivity, and unlock the power of collaboration with a cloud-based IDE. This AWS Cloud9 tutorial shows you how.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
