LIVEยทThe trends shaping tomorrow's world.
Future Tech

Terraform vs CloudFormation: How to Choose an IaC Tool

Terraform vs AWS CloudFormation compared on state, failure handling, drift, multi-account rollout, extensibility, licensing and cost, plus how to choose.

Terraform and AWS CloudFormation both let you describe infrastructure in files and have a tool build it. The short answer: pick CloudFormation if you only use AWS and want AWS to hold your deployment state and roll back failed deploys for you. Pick Terraform (or its open-source fork, OpenTofu) if you manage more than AWS, or want one workflow across clouds and SaaS tools. Everything else, from drift handling to multi-account rollout, follows from that one design difference.

If you're new to the idea itself, start with our infrastructure as code explainer. This article assumes you know what IaC is and focuses on the head-to-head.

The core difference: who holds the state

Every IaC tool needs a record of which real resources belong to which lines of code. The two tools put that record in very different places.

Terraform keeps a state file. By default it writes terraform.tfstate to local disk, and HashiCorp recommends HCP Terraform or a remote backend so teams can share it and don't lose it [2]. Before each operation Terraform refreshes that state against the real infrastructure, then uses it to decide what to change [2]. On AWS, the common pattern is the S3 backend. Locking, which stops two people applying at once, is opt-in there; you enable it with use_lockfile, and HashiCorp's docs mark the older DynamoDB-based locking as deprecated (as of November 2026) [3]. The docs also strongly recommend turning on S3 bucket versioning so you can recover a damaged state file [3].

CloudFormation keeps stacks. You write a template in YAML or JSON, and when you create a stack from it, CloudFormation provisions the resources and tracks them as a single unit [6][7]. There is no state file to store, lock, back up or secure. AWS holds that record inside the service.

That trade is the heart of the decision. Terraform's state file is a real operational asset: it can contain sensitive values [2], it must be protected, and losing it is painful. In exchange, the model lets Terraform manage anything with an API, not just AWS.

Side-by-side comparison


Terraform

AWS CloudFormation

What it manages

Any platform with a provider: AWS, Azure, Google Cloud, Kubernetes, GitHub, Datadog and thousands more [1]

AWS resources, plus third-party extensions from the CloudFormation registry [14]

Language

HCL configuration files [19]

YAML or JSON templates [7]

State

State file you store and lock (local by default; remote backend recommended) [2][3]

Managed by AWS as stacks [6]

Preview

terraform plan [1]

Change sets [8]

Failed deploy

Stops; no automatic rollback of a partial apply [4]

Rolls back by default (except in express mode); can preserve successful resources and retry instead [7][11]

Drift

Detected when plan refreshes state [2]

Drift detection; drift-aware change sets [9][10]

Many accounts and Regions

Separate states per account or Region, wired up by you

StackSets, one operation across accounts and Regions [13]

Adopting existing resources

import blocks [5]

IaC generator builds a template from existing resources [15]

Cost of the tool

CLI is a public binary download [20]; HCP Terraform is a separate managed service (check current pricing)

No charge for AWS resource types; registry extensions billed per handler operation [16]

Ownership

HashiCorp, part of IBM since February 27, 2025 [17]

AWS

What happens when a deploy fails

This is where teams feel the difference most.

CloudFormation rolls back. If a stack operation fails, CloudFormation by default rolls back: a failed create deletes the resources it made, and a failed update restores the last known working state [7]. AWS also offers the opposite choice: a "preserve successfully provisioned resources" option that keeps the successful resources and leaves the stack in a CREATE_FAILED or UPDATE_FAILED state, so you can investigate, fix the cause and retry from where it stopped [11]. Note that CloudFormation's faster express mode turns rollback off by default [11]. You can go further with rollback triggers, which watch CloudWatch alarms during a deployment and roll back if the application breaches a threshold you set [12].

Terraform stops. HashiCorp's tutorial is blunt about it: when an apply step errors, Terraform logs the error, updates the state file with whatever changes did succeed, unlocks the state and exits. "Terraform does not support automatically rolling back a partially-completed apply" [4]. You fix the problem and run apply again to reach the desired state.

Neither approach is strictly better. Automatic rollback is reassuring for a production stack at 2 a.m. A stop-and-fix model is more predictable for resources that are slow or risky to delete and recreate, such as databases. Know which behavior you're signing up for and write your runbooks around it.

Previewing changes: plan vs change sets

Both tools let you see a change before it happens.

  • terraform plan builds an execution plan describing what Terraform will create, update or destroy, and apply carries it out "on approval" in dependency order [1].
  • A CloudFormation change set previews how a template update will affect running resources, including whether anything will be deleted or replaced. Nothing changes until you execute it [8]. AWS notes that change sets don't guarantee success, though CloudFormation does run pre-deployment validation for common failure causes when it creates one [8].

In practice both become the review step in a pull-request workflow: the plan or change-set output goes into the review, and only approved changes are applied.

Drift: changes made outside the tool

Someone fixes a production issue by clicking in the console, and now reality no longer matches the code.

  • CloudFormation has explicit drift detection for whole stacks or individual resources [9]. Its newer drift-aware change sets compare the template with the actual state of resources, so you can see whether a deployment would overwrite an out-of-band fix, then either push the template values back or update the template to match reality [10].
  • Terraform surfaces drift as part of normal planning, because each operation starts with a refresh of real infrastructure into state [2]. The plan then shows the changes needed to bring resources back in line with the code.

Rolling out to many AWS accounts

Large AWS estates use dozens or hundreds of accounts. CloudFormation StackSets let an administrator account create, update or delete stacks across multiple accounts and Regions "with a single operation" from one template [13]. That's a strong, native fit for baselines such as logging, guardrail roles or network setup in every account.

Terraform can manage many accounts too, but the structure is yours to build: separate state per account or Region, provider configurations that assume roles, and a pipeline that runs them. Many platform teams are happy to own that, and it extends naturally to non-AWS targets. It is still more to design.

Extending beyond AWS

Terraform works through providers, plugins that talk to a platform's API. HashiCorp and the community have written thousands of them, covering AWS, Azure, Google Cloud, Kubernetes, Helm, GitHub, Splunk and Datadog among many others [1]. If your infrastructure includes a DNS provider, a monitoring SaaS and a second cloud, one Terraform workflow can cover all of it. For context on multi-cloud trade-offs, see our cloud computing guide.

CloudFormation's answer is the registry: extensions including resource types, modules and Hooks from AWS, third-party publishers or your own team [14]. That lets CloudFormation manage some non-AWS resources, but the ecosystem is far smaller, and registry extensions are billed per handler operation (create, update, delete, read or list) [16].

Bringing existing resources under management

Most teams adopt IaC after resources already exist.

  • Terraform uses an import block that names the real resource's ID and the address it should have in state, alongside a matching resource block in configuration [5].
  • CloudFormation's IaC generator scans resources in your account that CloudFormation doesn't yet manage and generates a template from them, which you can also migrate into an AWS CDK app [15].

Licensing, ownership and OpenTofu

Licensing matters more here than in most tool choices.

In 2023 HashiCorp moved Terraform from the Mozilla Public License v2.0 to the Business Source License v1.1 [18]. In response, the Linux Foundation announced OpenTofu on September 20, 2023, as an open-source alternative under neutral governance [18]. HashiCorp itself has been part of IBM since IBM completed its acquisition on February 27, 2025 [17]. Our IaC explainer covers the fork in more detail.

For most companies using Terraform internally, the license change has no practical effect. It matters if you build a product that competes with HashiCorp, or if your policy requires an OSI-approved license. Have your legal team read the actual terms. CloudFormation, by contrast, is simply an AWS service: no license to manage, and no use outside AWS.

Cost

CloudFormation charges nothing extra for provisioning AWS resource types; you pay for the resources themselves. Charges apply per handler operation when you use registry extensions [16]. The Terraform CLI is a public binary download with no sign-up or payment step [20]. HCP Terraform, HashiCorp's managed service for state, runs and policy, is sold in tiers whose terms change, so check the current pricing page rather than relying on figures quoted elsewhere.

The bigger cost is usually people: who writes the code, who maintains the pipeline, and who debugs a failed deploy at night.

How to choose

  1. Is everything you manage in AWS, and will it stay there? If yes, CloudFormation (often through the AWS CDK) is the lower-friction choice: no state file to secure, automatic rollback and native multi-account StackSets [6][11][13].
  2. Do you manage other clouds or SaaS platforms? Choose Terraform or OpenTofu. One language and workflow across providers outweighs most other differences [1].
  3. Which failure model fits your risk? Prefer automatic rollback? CloudFormation [11]. Prefer to stop, inspect and fix forward? Terraform [4].
  4. Who owns the platform? A dedicated platform team can run Terraform state, locking and pipelines well. A small team running purely on AWS may prefer to let AWS hold state. See our DevOps vs platform engineering piece for how those teams are organized.
  5. Licensing requirements. If you need an OSI-approved open-source license, evaluate OpenTofu alongside Terraform [18].
  6. What does your team already know? Existing skills and modules are a real asset. A switch costs migration time and retraining, so make sure the gain is concrete.

Mixing the two is common and fine: CloudFormation StackSets for account baselines, Terraform for application stacks and third-party services. Just keep each resource owned by exactly one tool.

Frequently asked questions

Is Terraform better than CloudFormation?

Neither is better in general. Terraform is the stronger choice when you manage more than AWS, because its providers cover thousands of platforms [1]. CloudFormation is often simpler for AWS-only estates because AWS manages state and rolls back failed deployments by default [6][11].

Does Terraform roll back a failed apply?

No. HashiCorp states that Terraform "does not support automatically rolling back a partially-completed apply." It records what succeeded in state and exits, and you fix the error and apply again [4].

Do I have to pay for CloudFormation?

Not for provisioning AWS resource types; you pay only for the AWS resources you create. Registry extensions such as third-party resource types and custom Hooks are charged per handler operation [16].

Can CloudFormation manage resources outside AWS?

To a limited degree. The CloudFormation registry supports third-party resource types, modules and Hooks [14], but the catalogue is much smaller than Terraform's provider ecosystem [1].

What is OpenTofu, and should I use it instead of Terraform?

OpenTofu is a Linux Foundation project launched in September 2023 as an open-source alternative to Terraform after HashiCorp moved Terraform to the Business Source License [18]. It suits teams that require an open-source license or neutral governance. Test your modules and providers with it before switching.

Can I use both Terraform and CloudFormation?

Yes, and many organizations do. The rule that matters is that each resource should be owned by one tool only, so their records don't fight over the same infrastructure.

Sources

  1. HashiCorp, "What is Terraform?"
  2. HashiCorp, "State (Terraform language documentation)"
  3. HashiCorp, "Backend type: s3"
  4. HashiCorp, "Apply Terraform configuration (tutorial)"
  5. HashiCorp, "Import resources overview"
  6. Amazon Web Services, "What is CloudFormation?"
  7. Amazon Web Services, "CloudFormation concepts"
  8. Amazon Web Services, "Update CloudFormation stacks using change sets"
  9. Amazon Web Services, "Detect unmanaged configuration changes to stacks and resources with drift detection"
  10. Amazon Web Services, "Using drift-aware change sets"
  11. Amazon Web Services, "Choose how to handle failures when provisioning resources"
  12. Amazon Web Services, "Roll back your CloudFormation stack on alarm breach with rollback triggers"
  13. Amazon Web Services, "Managing stacks across accounts and Regions with StackSets"
  14. Amazon Web Services, "Managing extensions with the CloudFormation registry"
  15. Amazon Web Services, "Generate templates from existing resources with IaC generator"
  16. Amazon Web Services, "AWS CloudFormation pricing"
  17. IBM, "IBM Completes Acquisition of HashiCorp, Creates Comprehensive, End-to-End Hybrid Cloud Platform" (February 27, 2025)
  18. The Linux Foundation, "Linux Foundation Launches OpenTofu: A New Open Source Alternative to Terraform" (September 20, 2023)
  19. HashiCorp, "Configuration syntax"
  20. HashiCorp, "Install Terraform"