Skip to main content
Terraform vs CloudFormation on AWS: Which to Use

Terraform vs CloudFormation on AWS: Which to Use

KU
· Founder & Chief Editor
• 8 min read•Updated •23 views

A practitioner's comparison of Terraform and CloudFormation on AWS covering state, drift, new-service lag, rollback, and where CDK fits.

Key takeaways

  • Pick Terraform if you manage anything beyond AWS, want the module registry, or prefer HCL and an explicit plan.
  • Pick CloudFormation, usually through CDK, if you are strictly AWS-only, want AWS to hold state, and deploy across many accounts with StackSets.
  • Terraform needs a remote backend; CloudFormation needs patience with stuck rollbacks.

Use Terraform if anything you manage lives outside AWS (DNS, monitoring, GitHub, Kubernetes) or you want the module registry and a readable plan. Use CloudFormation, ideally through CDK, if you are strictly AWS-only, want AWS to own state, and fan out across accounts with StackSets. For most teams we default to Terraform.

Verified against

Terraform 1.17.1 (released 2026-10-28), Terraform AWS provider 6.71.0, against the HashiCorp S3 backend docs and the AWS CloudFormation User Guide pages on drift detection, stack failure options and StackSets. Checked October 2026.

Both tools provision real resources from declarative files, both are mature, and the wrong pick will not sink you. It will shape how your team works for years, so match it to how many providers and accounts you actually run.

The comparison at a glance

AttributeTerraformCloudFormation
ScopeAny provider: AWS, Cloudflare, Datadog, GitHub, KubernetesAWS resources only
StateYour state file in a remote backend (S3 with use_lockfile)Held by AWS per stack, nothing to store
DriftEvery terraform plan refreshes and shows itOn-demand drift detection, some resource types NOT_CHECKED
Failed applyStops, you fix forwardRolls back by default; can preserve resources and retry
Multi-account fan-outModules plus a wrapper (Terragrunt, CI matrix)StackSets, native to AWS Organizations
LicenseBusiness Source License 1.1 since 1.6.0 (OpenTofu is the MPL fork)AWS service, no license to track

Multi-cloud vs AWS-only

This is the cleanest dividing line. CloudFormation provisions AWS resources and nothing else. That is a scope decision rather than a weakness, and if your estate is AWS and staying that way, it buys first-party integration.

Most real stacks are not that pure. You configure a DNS record in Cloudflare, a monitor in Datadog and a bucket in S3 in the same change. Terraform does that in one plan; CloudFormation cannot. Once any non-AWS resource is under management, Terraform stops being optional. If the license change bothers you, Terraform vs OpenTofu covers the fork, which keeps the same HCL and workflow.

State management: the biggest philosophical split

CloudFormation tracks what each stack owns on the service side. There is no file to store, lock or corrupt, and that is the feature people underrate most.

Terraform keeps its own state, and you are responsible for it. On AWS that means an S3 backend. As of Terraform 1.17 the backend docs mark DynamoDB-based locking as deprecated, to be removed in a future minor version, and recommend S3-native locking instead:

HCL
# infra/backend.tf
terraform {
  backend "s3" {
    bucket       = "acme-tfstate-prod"
    key          = "network/terraform.tfstate"
    region       = "us-east-1"
    use_lockfile = true
    encrypt      = true
  }
}

use_lockfile defaults to false, so set it explicitly. The payoff for owning state is control: terraform state mv, import blocks and terraform state rm let you refactor and migrate in ways CloudFormation does not allow. Our Terraform state migration walkthrough shows that in practice.

Drift: always-on vs on-demand

Terraform surfaces drift on every plan. To see only what changed outside Terraform, without proposing fixes:

code
$ terraform plan -refresh-only

CloudFormation drift detection runs when you ask for it:

code
$ aws cloudformation detect-stack-drift --stack-name network-prod
$ aws cloudformation describe-stack-resource-drifts --stack-name network-prod \
    --stack-resource-drift-status-filters MODIFIED DELETED

The AWS docs list the limits: resource types that do not support drift detection come back NOT_CHECKED, nested stacks are not checked from the parent, and only properties you set explicitly are compared, not defaults. Usable, but you have to schedule it.

Rollback behavior

CloudFormation rolls back a failed stack operation to the last known-good state by default. That is a real safety net until the rollback itself fails and leaves the stack in UPDATE_ROLLBACK_FAILED, a genuinely painful place. AWS now gives you a middle path: --disable-rollback (the console calls it "Preserve successfully provisioned resources") keeps what succeeded so you can fix and retry, and rollback-stack reverts on demand. In the newer express mode, rollback is off by default.

Terraform never rolls back. A half-failed apply leaves real resources in place and recorded in state; you read the error, fix the config, and apply again. Terraform gives you control and expects competence; CloudFormation gives you guardrails and occasionally traps you inside them.

Ergonomics, and CDK as the escape hatch

The same versioned bucket in both:

HCL
# infra/logs.tf
resource "aws_s3_bucket" "logs" {
  bucket = "acme-app-logs-prod"
  tags   = { Environment = "prod", Team = "platform" }
}

resource "aws_s3_bucket_versioning" "logs" {
  bucket = aws_s3_bucket.logs.id
  versioning_configuration {
    status = "Enabled"
  }
}
YAML
# templates/logs.yaml
Resources:
  LogsBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: acme-app-logs-prod
      VersioningConfiguration:
        Status: Enabled
      Tags:
        - Key: Environment
          Value: prod
        - Key: Team
          Value: platform

HCL has expressions, for_each, conditionals and clean interpolation. CloudFormation leans on !Ref, !Sub and !GetAtt, which work but get verbose. If you want CloudFormation's engine without the YAML, the AWS CDK lets you write TypeScript, Python, Java, C# or Go and synthesizes templates underneath. Our Pulumi vs AWS CDK piece goes deeper on that route.

Where CloudFormation wins outright: StackSets. Pushing one stack to every account and region in an AWS Organization, with new accounts picked up automatically, has no single Terraform equivalent; you assemble it from modules, provider aliases and a wrapper such as Terragrunt.

Where Terraform wins outright: the Registry. Vetted modules for VPCs, EKS and RDS save a week of subnet wiring, and versioning shared modules keeps that reuse safe. CloudFormation has nothing at that scale.

New-service support is closer than its reputation. AWS-built services often reach CloudFormation at or near launch, but not always, and the Terraform AWS provider ships on its own cadence (6.71.0 landed the same week as Terraform 1.17.1). When a resource is missing, the awscc provider, generated from the CloudFormation registry, is the usual stopgap.

Errors you will hit, and the fix

Error textToolFix
Error: Error acquiring the state lockTerraformAnother run holds the lock; wait, or terraform force-unlock <ID> once you are sure it is dead (full walkthrough)
UPDATE_ROLLBACK_FAILEDCloudFormationFix the blocking resource, then aws cloudformation continue-update-rollback --stack-name X, adding --resources-to-skip for resources that cannot recover
No updates are to be performed.CloudFormationNot a failure; in CI use aws cloudformation deploy --no-fail-on-empty-changeset
BucketAlreadyExistsBothS3 names are global; add an account or region suffix

Where this breaks

The "default to Terraform" advice weakens in three cases. Regulated shops that forbid third-party binaries in the deploy path are better served by CloudFormation or CDK. Landing zones spanning dozens of accounts lean on StackSets and AWS Control Tower, which are CloudFormation underneath. And a team with no one willing to own state hygiene will eventually corrupt or leak a state file; CloudFormation removes that whole class of incident.

Questions people ask

Is Terraform better than CloudFormation?

For most teams, yes, because real infrastructure spans more than AWS and Terraform manages it all in one plan, with a large module registry and readable HCL. CloudFormation is better when you are strictly AWS-only, want AWS to hold state, or deploy org-wide with StackSets. Many AWS-native teams get the best of CloudFormation by writing CDK code instead of raw YAML.

Does Terraform still need DynamoDB for state locking?

No. As of Terraform 1.17, the S3 backend supports native locking with use_lockfile = true, which writes a lock object next to the state file. HashiCorp's docs mark DynamoDB-based locking as deprecated and slated for removal in a future minor version. Existing setups still work, but new backends should use the lockfile and drop the DynamoDB table after migrating.

Does CloudFormation roll back automatically?

By default, yes: a failed create or update reverts to the last stable state. You can opt out per operation with --disable-rollback, which keeps successfully provisioned resources so you can fix and retry, then use rollback-stack if you change your mind. Express mode disables rollback by default. A rollback that fails leaves UPDATE_ROLLBACK_FAILED, cleared with continue-update-rollback.

The call we'd make

For most teams shipping today, we reach for Terraform. The multi-provider reality of modern infrastructure, the Registry and the plan output outweigh the state chore, which an S3 backend with use_lockfile solves once. We recommend CloudFormation, through CDK, when a team is strictly AWS-only, deploys across dozens of accounts with StackSets, or cannot have third-party tooling in the supply chain. The mistake is picking on vibes instead of counting your providers and accounts. For the wider field, see our guide to the best Infrastructure-as-Code tools.

Sources

Explore topics:TerraformAWSDevOps
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). Terraform vs CloudFormation on AWS: Which to Use. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/terraform-vs-cloudformation

Markdown

[Terraform vs CloudFormation on AWS: Which to Use](https://www.devopsness.com/blog/terraform-vs-cloudformation) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

586 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.