Table of Contents
Overview
Terraform is an open-source, multi-cloud IaC tool by HashiCorp using HCL syntax. CloudFormation is AWS’s native IaC service using JSON/YAML templates. Both automate infrastructure provisioning, but they take fundamentally different approaches.
Multi-Cloud Support
Terraform: Supports 3000+ providers — AWS, Azure, GCP, Kubernetes, Datadog, PagerDuty, and more. Write once, deploy anywhere.
CloudFormation: AWS only. If you need Azure or GCP resources, you need a different tool.
Winner: Terraform, by a wide margin.
Language & Syntax
Terraform (HCL):
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
tags = { Name = "web-server" }
}
CloudFormation (YAML):
Resources:
WebServer:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0c55b159cbfafe1f0
InstanceType: t3.micro
Tags:
- Key: Name
Value: web-server
HCL is more concise and readable. CloudFormation YAML can be verbose but is familiar to AWS users.
State Management
Terraform: Explicit state file (terraform.tfstate) that you manage — local or remote (S3, Azure Blob, Terraform Cloud). Requires state locking for teams.
CloudFormation: State is fully managed by AWS. No state files to worry about. Stacks track all resources automatically.
Winner: CloudFormation for simplicity; Terraform for control.
Modularity & Reuse
Terraform: First-class module system with the Terraform Registry hosting thousands of community modules. Modules accept variables and return outputs.
CloudFormation: Nested stacks and StackSets for reuse. AWS Service Catalog for organizational templates. Less flexible than Terraform modules.
Drift Detection
Terraform: terraform plan shows drift on every run. Refresh state with terraform refresh.
CloudFormation: Built-in drift detection via console or CLI. Can detect changes to stack resources.
When to Use Each
Choose Terraform when:
- You use multiple cloud providers
- You want maximum flexibility and community support
- You need to manage non-cloud resources (DNS, monitoring, etc.)
- Your team already knows HCL
Choose CloudFormation when:
- You’re 100% AWS with no plans to change
- You want zero state management overhead
- You need deep integration with AWS services (Service Catalog, Control Tower)
- Your organization mandates AWS-native tools
Hands-On Courses
Learn by doing with interactive courses on CopyPasteLearn:
Conclusion
For most teams, Terraform is the better choice due to its multi-cloud support, mature ecosystem, and flexible state management. CloudFormation remains a solid option for AWS-only shops that value simplicity and native integration. Many organizations use both — CloudFormation for core AWS infrastructure and Terraform for everything else.

