Every infrastructure-as-code example so far in this domain and the Cloud Computing domain has used Terraform — for a real reason, not an oversight. CloudFormation is AWS's own native alternative, and understanding what it actually trades off against Terraform matters for reading real AWS documentation and working on teams that chose differently.
4 min read
Both CloudFormation and Terraform solve the same core problem from the Cloud Computing domain's IaC lesson — declare infrastructure as code instead of clicking through a console — but they differ in scope and philosophy in ways that matter practically:
| CloudFormation | Terraform | |
|---|---|---|
| Provider scope | AWS only | Any provider (AWS, GCP, Azure, and hundreds of others) via providers |
| Language | YAML or JSON | HCL (HashiCorp Configuration Language) |
| State management | Managed by AWS automatically | You manage state yourself (typically in S3 + DynamoDB for locking) |
| New AWS feature support | Usually available immediately (AWS's own product) | Depends on the AWS provider being updated (usually fast, but a separate release) |
| Multi-cloud | Not applicable | A genuine advantage if it's ever needed |
The same kind of S3 bucket resource seen throughout this domain in Terraform, in CloudFormation:
AWSTemplateFormatVersion: "2010-09-09"
Resources:
AppUploadsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-app-uploads-unique-name
VersioningConfiguration:
Status: Enabled
Outputs:
BucketName:
Value: !Ref AppUploadsBucketaws cloudformation deploy \
--template-file bucket.yaml \
--stack-name app-uploads-stackStructurally similar to the Terraform equivalent — resources, properties, outputs — but state is entirely AWS's problem: a CloudFormation stack tracks what it created and its current status internally, with no separate state file to store, secure, or lock yourself.
Terraform's provider model is the deciding factor for most teams: a single Terraform configuration can declare AWS resources, a Cloudflare DNS record, a Datadog monitor, and a GitHub repository setting, all in one place, using one consistent language and workflow — something CloudFormation structurally cannot do, since it only understands AWS resources. Even for a team that's genuinely AWS-only today, that flexibility is cheap optionality: if a non-AWS dependency (a DNS provider, a monitoring tool, a SaaS integration) ever needs to be managed as code, Terraform already supports it without adopting a second IaC tool.
This isn't one-sided — CloudFormation has genuine strengths that matter in specific contexts:
Worth knowing about even briefly: AWS CDK lets you define infrastructure in TypeScript, Python, or another supported language, then synthesizes it down to a CloudFormation template at deploy time — combining a real programming language's abstractions (loops, functions, classes) with CloudFormation's AWS-native state management underneath.
const bucket = new s3.Bucket(this, 'AppUploads', {
versioned: true,
bucketName: 'my-app-uploads-unique-name',
});This produces (roughly) the same CloudFormation template shown earlier, generated from actual TypeScript rather than hand-written YAML — a real option for a team that wants CloudFormation's state-management model but finds YAML awkward for anything with real logic or repetition.
Neither tool is simply "correct" — Terraform's multi-provider flexibility and this curriculum's own consistent use of it (matching most real-world teams outside pure AWS-native shops) makes it the default worth learning first; CloudFormation (or CDK) is worth knowing at least at a reading level, since a genuinely large fraction of official AWS documentation, examples, and AWS-native tooling assumes it, and a team that chose CloudFormation for good reasons (heavy AWS SAM/CDK usage, wanting AWS to own state management entirely) isn't making an unreasonable choice.
Check your understanding
A quick comprehension check — not tracked, not graded, just for you.
1. What is the core structural difference between CloudFormation and Terraform?
2. What is the main reason most teams outside pure-AWS shops default to Terraform?
3. What genuine advantage does CloudFormation have over Terraform?
4. What does AWS CDK actually do?
AWS