TerraformPilot

Terraform

Terraform vs CloudFormation - Which IaC Tool Should You Choose

Compare Terraform vs AWS CloudFormation — multi-cloud support, state management, language, ecosystem, and when to use each for infrastructure as code.

LLuca Berton2 min read

Quick Answer

#

Choose Terraform if you use multiple cloud providers or want provider-agnostic IaC. Choose CloudFormation if you're 100% AWS and want native integration with no state management overhead.

Feature Comparison

#
FeatureTerraformCloudFormation
Multi-cloud✅ AWS, Azure, GCP, 3000+ providers❌ AWS only
LanguageHCL (HashiCorp Configuration Language)JSON or YAML
State managementYou manage (S3, Terraform Cloud)AWS manages automatically
Drift detectionterraform plan (manual)Built-in (automatic)
RollbackManual (apply previous config)Automatic on failure
PricingFree (OSS) / Paid (Cloud)Free (included with AWS)
ModulesTerraform Registry (15,000+)Nested stacks, CDK constructs
Preview changesterraform planChange Sets
Import existingterraform importresource import (since 2023)
Learning curveModerate (HCL)Moderate (YAML/JSON)

Language Comparison

#

Terraform (HCL)

#
resource "aws_s3_bucket" "data" {
  bucket = "my-data-bucket-${var.environment}"
 
  tags = {
    Environment = var.environment
    ManagedBy   = "terraform"
  }
}
 
resource "aws_s3_bucket_versioning" "data" {
  bucket = aws_s3_bucket.data.id
  versioning_configuration {
    status = "Enabled"
  }
}

CloudFormation (YAML)

#
Resources:
  DataBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub "my-data-bucket-${Environment}"
      VersioningConfiguration:
        Status: Enabled
      Tags:
        - Key: Environment
          Value: !Ref Environment
        - Key: ManagedBy
          Value: cloudformation
 
Parameters:
  Environment:
    Type: String
    Default: dev

When to Choose Terraform

#
  • Multi-cloud — you use AWS + Azure, AWS + GCP, or plan to
  • Third-party services — you manage Datadog, PagerDuty, GitHub, Cloudflare alongside infrastructure
  • Team familiarity — team already knows HCL
  • Module ecosystem — rich library of reusable modules on Terraform Registry
  • Provider flexibility — 3,000+ providers, community-driven

When to Choose CloudFormation

#
  • AWS-only — you're 100% committed to AWS
  • No state management — AWS handles state and locking automatically
  • Automatic rollback — failed deployments roll back to previous state
  • Native integration — works with AWS Organizations, Service Catalog, Control Tower
  • StackSets — deploy across multiple AWS accounts and regions

State Management

#

Terraform

#

You're responsible for state:

terraform {
  backend "s3" {
    bucket         = "my-tf-state"
    key            = "prod/terraform.tfstate"
    region         = "us-east-1"
    dynamodb_table = "terraform-locks"
    encrypt        = true
  }
}

CloudFormation

#

AWS manages state automatically. No backend configuration needed. Drift detection is built in:

aws cloudformation detect-stack-drift --stack-name my-stack

Migration Paths

#

CloudFormation → Terraform

#
# 1. List CloudFormation resources
aws cloudformation list-stack-resources --stack-name my-stack
 
# 2. Write Terraform config for each resource
 
# 3. Import into Terraform state
terraform import aws_s3_bucket.data my-data-bucket
 
# 4. Verify
terraform plan  # Should show no changes
 
# 5. Delete CloudFormation stack with DeletionPolicy: Retain

Terraform → CloudFormation

#
# 1. terraform state rm each resource (keeps cloud resources)
# 2. Create CloudFormation template
# 3. Import resources into CloudFormation stack
aws cloudformation create-stack --stack-name my-stack \
  --template-body file://template.yaml \
  --parameters ParameterKey=...,ParameterValue=...

Common Misconceptions

#
MythReality
"Terraform is always better"CloudFormation has better rollback and zero state overhead
"CloudFormation is simpler"YAML templates get verbose fast; Terraform HCL is more concise
"You can't use both"Many teams use both — CFN for foundational AWS, Terraform for app infra
"Terraform can't do X on AWS"AWS provider covers 99%+ of services
#

Conclusion

#

Both are production-ready IaC tools. Terraform wins on multi-cloud, ecosystem, and language expressiveness. CloudFormation wins on zero state management, automatic rollback, and native AWS integration. Many enterprises use both — CloudFormation for foundational AWS infrastructure and Terraform for application-level resources and multi-cloud services.

#Terraform#AWS#Infrastructure as Code#DevOps#CloudFormation

Share this article