Terraform vs CloudFormation
Compare a multi-provider infrastructure-as-code tool with AWS-native stack-based provisioning.
Infrastructure
Terraform
Terraform is a provider-based infrastructure-as-code tool that works across many cloud providers, platforms, and services. It is widely used for standardizing infrastructure workflows across environments.
Infrastructure
AWS CloudFormation
CloudFormation is AWS’s native infrastructure-as-code service. It provisions AWS resources through stack-based templates and integrates directly with AWS service lifecycle behavior.
Key Differences
Terraform supports many providers and platforms, while CloudFormation is AWS-native and focused on AWS resources.
Terraform is often preferred for multi-cloud or provider-agnostic workflows, while CloudFormation is often preferred in AWS-only environments.
Terraform uses explicit state files and its own planning and apply workflow, while CloudFormation manages AWS resource stacks natively.
CloudFormation is deeply integrated into AWS, while Terraform is broader and often more portable across environments.
Terraform skills often transfer more easily across tools and providers, while CloudFormation expertise is more AWS-specific.
CloudFormation may feel more natural for teams fully committed to AWS, while Terraform often feels more flexible for broader infrastructure strategy.
When to Use
When to use Terraform
Use Terraform when you want one infrastructure-as-code workflow across multiple providers, platforms, or service types beyond AWS alone.
When to use CloudFormation
Use CloudFormation when your infrastructure is fully AWS-based and you want native stack lifecycle behavior integrated directly into AWS services.
Tradeoffs
Terraform is more flexible and broader, but introduces external state management and another abstraction layer.
CloudFormation is AWS-native and often simpler in AWS-only shops, but much less portable outside AWS.
Terraform is often stronger for standardization across environments, while CloudFormation is stronger for native AWS alignment.
Common Mistakes
Choosing CloudFormation in environments that clearly need multi-provider flexibility.
Choosing Terraform by default even when a team is entirely AWS-native and prefers deeper AWS-native workflows.
Ignoring operational state management differences between the two models.
Interview Tip
A good short answer is: CloudFormation is AWS-native and stack-based, while Terraform is broader, more portable, and multi-provider.