DevOps

Terraform vs CloudFormation: A Practical Guide

Infrastructure as code (IaC) is no longer optional for startups that want to scale. The question is which tool to use. The two most popular options are HashiCorp Terraform and AWS CloudFormation. Both let you define your infrastructure in configuration files and apply changes through a predictable workflow. But they have fundamentally different approaches, and the right choice depends on your situation.

The core difference

CloudFormation is AWS-native. It is built by AWS, for AWS. Every new AWS service gets CloudFormation support on launch day (usually). It uses JSON or YAML templates and manages state internally. You do not need to worry about state files, locking, or backends. It is free to use.

Terraform is cloud-agnostic. It supports AWS, GCP, Azure, and hundreds of other providers through its plugin system. It uses HCL (HashiCorp Configuration Language), which is more readable than JSON/YAML. It manages state in a file that you need to store somewhere (S3, Terraform Cloud, or locally). It is open source and free, with paid options for team collaboration.

When to choose CloudFormation

Choose CloudFormation if all of the following are true:

  • You are 100% on AWS and have no plans to use other cloud providers.
  • Your infrastructure team is small (1 to 3 people) and you want minimal tooling overhead.
  • You prefer managed services and do not want to worry about state management.
  • You are already using AWS CDK, SAM, or other AWS-native tools.

CloudFormation's biggest advantage is zero operational overhead. There is no state file to manage, no backend to configure, and no version upgrades to track. You write a template, deploy it through the AWS console or CLI, and CloudFormation handles the rest. For small teams that want to stay lean, this simplicity is valuable.

When to choose Terraform

Choose Terraform if any of the following are true:

  • You use multiple cloud providers or plan to in the future.
  • You manage resources outside of AWS (DNS, monitoring, CDN, SaaS tools).
  • You value readable, maintainable configuration files.
  • You want a vibrant ecosystem of community modules.
  • Your infrastructure team will grow beyond 3 people.

Terraform's biggest advantage is flexibility. With a single tool and a single language, you can manage your AWS infrastructure, your Cloudflare DNS records, your Datadog monitors, your PagerDuty schedules, and your GitHub repositories. This unified workflow becomes increasingly valuable as your infrastructure grows in complexity.

Language comparison

HCL (Terraform) is purpose-built for infrastructure configuration. It has variables, loops, conditionals, modules, and data sources. It reads naturally and is easy to review in pull requests.

CloudFormation JSON/YAML is verbose and harder to read. Conditions, references, and intrinsic functions use a syntax that is powerful but not intuitive. AWS CDK (Cloud Development Kit) addresses this by letting you write infrastructure in TypeScript, Python, or Java, which then generates CloudFormation templates. If you choose CloudFormation, strongly consider using CDK instead of raw templates.

State management

This is where Terraform gets complicated. Terraform tracks the state of your infrastructure in a state file. This file must be stored somewhere accessible to everyone who runs Terraform, it must be locked to prevent concurrent modifications, and it must be backed up.

The standard approach is to store state in S3 with DynamoDB for locking. Terraform Cloud handles this for you with a managed backend. Either way, you need to think about state management from day one. A corrupted or lost state file can be a significant incident.

CloudFormation does not have this problem. State is managed by AWS internally. You never see it, touch it, or worry about it.

Drift detection

Both tools can detect when someone makes a manual change to infrastructure that does not match the configuration. CloudFormation has built-in drift detection. Terraform detects drift on every plan/apply cycle. In practice, Terraform is better at this because it checks drift proactively every time you run it, while CloudFormation drift detection must be triggered manually.

The practical recommendation

For most startups in 2025, we recommend Terraform. The multi-cloud flexibility, better language, larger ecosystem, and stronger community make it the more future-proof choice. The state management complexity is real but manageable with proper setup.

If you are a very small team (1 to 2 engineers), entirely on AWS, and want to minimize operational overhead, CloudFormation with CDK is a perfectly valid choice. You can always migrate to Terraform later if your needs change.

Whichever tool you choose, the important thing is to use one. Managing infrastructure through the AWS console and ad-hoc CLI commands does not scale. Infrastructure as code gives you repeatability, auditability, and the ability to recreate your entire environment from scratch. That capability is worth the investment in learning either tool.

Not ready for a call? Same.

Get the playbook, not a sales pitch

If this was useful, Jacob sends a few short, practical notes on cutting cloud spend and scaling infra the right way. No fluff, unsubscribe in one click. Just reply if you want to talk; it reaches him directly.

From Jacob Masse, founder of traztech. No spam, unsubscribe in one click.

Need help with any of this?

We help startups build secure, scalable infrastructure. Book a free strategy call and let\'s talk about your stack.

Book a free consultation