DevOpsintermediate

Terraform vs AWS CloudFormation

Terraform vs AWS CloudFormation compared for 2026: Terraform 1.17 with HCL, providers, state files, S3 lockfiles, import blocks, tests, ephemeral values and HCP Terraform vs CloudFormation with managed stacks, change sets, express mode, drift-aware change sets, StackSets, IaC generator, Hooks and Git sync, with real quotas, pricing, a validation example we ran and a clear pick per situation.

Quick Answer

Terraform and CloudFormation both turn declarative files into AWS infrastructure, but they put the hard parts in different places. Terraform (1.17.2, 11 November 2026) is a single CLI that talks to any API through providers; the Terraform Registry API lists about 7,760 of them, and the AWS provider shipped 6.73.0 the same day. You own the state file: it holds the mapping between your code and real resources, can contain secrets, and needs a backend with locking (the S3 backend now locks with a lockfile and has deprecated DynamoDB locking). Since 1.6 Terraform is under the Business Source License, with IBM as licensor. CloudFormation is an AWS service: AWS keeps the state, rolls back failed deployments automatically, previews changes with change sets, detects drift, deploys across accounts and Regions with StackSets, and charges nothing for AWS::* resources (third-party resource types and custom Hooks cost $0.0009 per handler operation after 1,000 free per month). Its walls are AWS-only coverage and hard template quotas such as 500 resources per template. Pick CloudFormation (or the CDK on top of it) for AWS-only estates that want managed state and rollback; pick Terraform when you manage more than AWS, want one workflow for SaaS, Kubernetes and DNS too, or need fast plan/apply loops in CI.

Last updated November 16, 2026. Covers Terraform 1.17.2 (11 November 2026) with 1.17.0 (21 October 2026) and 1.16.7, the AWS provider 6.73.0 and awscc 1.110.0, and AWS CloudFormation as documented on 16 November 2026 (pricing, quotas, change sets, express mode, drift-aware change sets, StackSets, IaC generator, stack refactoring, Hooks, Git sync), with cfn-lint 1.60.1 and AWS CDK 2.277.0, plus a validation run of both tools on 16 November 2026.

Feature comparison of Terraform vs AWS CloudFormation
FeatureTerraformAWS CloudFormation
License & Ownership
Business Source License 1.1 for 1.6.0+, licensor IBM; production use allowed except competing hosted or embedded offerings
Proprietary managed AWS service; cfn-lint, CDK and the CloudFormation CLI are open source
What It Can Manage
Any platform with a provider; AWS via hashicorp/aws 6.73.0 and the Cloud Control-based awscc 1.110.0
AWS resource types plus registry extensions (third-party public types, private types, modules, Hooks)
Authoring Language
HCL (HashiCorp Configuration Language), declarative, with reusable modules
JSON or YAML templates; the AWS CDK generates them from TypeScript, JavaScript, Python, Java, C#/.NET or Go
State Storage
terraform.tfstate you store: local file by default, a remote backend (S3, etc.) or HCP Terraform
Managed by CloudFormation as stacks; nothing to store yourself
Concurrency & Locking
Automatic when the backend supports it; S3 backend use_lockfile (opt-in), DynamoDB locking deprecated; force-unlock by lock ID
Handled by the service; no lock table or lock file to manage
Change Preview
terraform plan (refresh + diff); new -minimal-refresh option in 1.17
Change sets, with pre-deployment validation of syntax, name conflicts and service quotas
Failed Deployment Behaviour
None automatic; partial applies stay in place and you fix forward
Automatic rollback on error by default; 'preserve successfully provisioned resources' option; express mode disables rollback unless re-enabled
Drift Detection
Visible in any plan; scheduled drift detection and continuous validation only in HCP Terraform Standard and Premium
Built-in drift detection on stacks, resources and StackSets; drift-aware change sets
Importing Existing Resources
import blocks (single resources or batches) and query-based bulk import
Manual resource import, auto-import by custom name, import whole stacks into StackSets
Generate Code From Live Resources
terraform plan -generate-config-out writes HCL for imported resources
IaC generator scans a Region (scan valid 30 days) and builds a template or a CDK app
Moving & Refactoring Resources
moved blocks to rename or move resources between modules without recreation
Stack refactoring moves resources between up to 5 stacks (CLI) and renames logical IDs
Multi-account / Multi-region
Multiple provider configurations/aliases per account and region; Stacks in HCP Terraform (max 20 deployments, 100 components, 10,000 resources per Stack)
StackSets: 1,000 stack sets per admin account, 100,000 instances per stack set, self- or service-managed permissions
Reuse & Modules
Modules from the public or private registry
Nested stacks, registry modules (100 per account and Region), macros
Testing & Linting
terraform test (.tftest.hcl), mock providers, terraform validate and fmt
cfn-lint (offline validation against the resource spec), CloudFormation Guard, change sets
Policy as Code
Terraform Policy (HCL, needs 1.17+), Sentinel and OPA in HCP Terraform
CloudFormation Hooks: Control Tower proactive controls, Guard rules, Lambda or custom Hooks that fail or warn
Secrets Handling
Values can land in state; ephemeral resources and write-only arguments avoid that for supported attributes
Dynamic references to SSM Parameter Store secure strings and Secrets Manager (60 per template)
Hard Limits Worth Knowing
No template-size or resource-count cap in the CLI; Stacks have the limits listed above
500 resources per template, 2,000 stacks per account (adjustable), 2,500 resources per nested-stack operation
Git-driven Deployments
Bring your own CI, or HCP Terraform VCS-driven runs
Git sync for GitHub, GitHub Enterprise, GitLab, GitLab self-managed and Bitbucket in 17 Regions
Pricing
CLI free under BSL; HCP Terraform free for small teams, paid editions for more than five users (prices not readable this run)
8/10
Free for AWS::*, Alexa::* (and Custom::*); third-party types and custom Hooks $0.0009 per handler operation after 1,000 free per month
10/10
Latest Release (Nov 2026)
1.17.2 (11 Nov 2026); 1.16.7 (22 Oct 2026)
Managed service (no versions); cfn-lint 1.60.1 (12 Nov 2026), AWS CDK 2.277.0 (13 Nov 2026)

Terraform

Terraform is HashiCorp's infrastructure as code CLI; IBM is now the licensor named in its licence. You describe resources in HCL, Terraform builds a dependency graph, shows a plan of what it will create, change or destroy, and applies it through providers that wrap each platform's API. It records what it manages in a state file that you store locally, in a remote backend such as S3, or in HCP Terraform, HashiCorp's hosted service for remote runs, shared state, policy and drift checks. Versions 1.6.0 and later are licensed under the Business Source License 1.1.

Pros

  • One workflow for AWS, other clouds, Kubernetes, DNS, SaaS and on-prem APIs: the registry API lists roughly 7,760 providers
  • terraform plan gives a fast, readable diff before every apply, and the CLI runs anywhere: macOS, Windows, Linux (including arm64 and s390x) and FreeBSD builds
  • Native testing with terraform test (.tftest.hcl files) since 1.6, with provider mocking since 1.7, so modules can be unit-tested without creating resources
  • Import blocks with -generate-config-out, plus query-based bulk import, make adopting existing infrastructure a reviewed code change
  • Ephemeral resources and write-only arguments (for example password_wo on aws_db_instance) keep selected secrets out of state and plan files
  • Terraform Policy (HCL-based) became GA in 1.17, alongside Sentinel and OPA in HCP Terraform

Cons

  • You own state: losing or leaking terraform.tfstate is a real incident, and HashiCorp says not to keep it in version control
  • Business Source License since 1.6, not an OSI open-source licence; the fork OpenTofu exists if that matters to you
  • No automatic rollback: a failed apply leaves whatever was created, and you fix forward with another plan and apply
  • Drift detection and continuous validation are HCP Terraform Standard/Premium features; the free CLI only shows drift when you run a plan
  • terraform validate needs terraform init first to download provider schemas, so linting in CI needs registry access or a provider mirror

Best For

Teams managing more than AWS (other clouds, Kubernetes, Helm, GitHub, Datadog and the like) who want one language, one plan/apply workflow and are willing to own state storage and locking.

AWS CloudFormation

AWS CloudFormation is AWS's built-in infrastructure as code service. You write JSON or YAML templates (or generate them with the AWS CDK), and CloudFormation creates, updates and deletes the resources as a stack, keeping state on the AWS side. It previews changes with change sets, rolls back failed operations automatically by default, detects drift, deploys stacks across accounts and Regions with StackSets, and can be extended with registry types and Hooks.

Pros

  • No state file to store, lock or protect: the stack is the state, managed by AWS
  • Automatic rollback on error by default, with an option to preserve successfully provisioned resources while you debug
  • Built-in drift detection, plus drift-aware change sets that compare live state, the last deployment and the new template
  • StackSets deploy one template to many accounts and Regions (up to 100,000 stack instances per stack set) with AWS Organizations integration
  • No extra charge for AWS::* and Alexa::* resources; you pay only for what the stack creates
  • IaC generator, auto-import and stack refactoring help bring existing resources under management and reorganize stacks

Cons

  • AWS only; anything outside AWS needs third-party registry types (billed per handler operation) or a different tool
  • Hard template quotas: 500 resources, 200 parameters, 200 outputs, 51,200-byte inline template body (1 MB via S3)
  • Raw YAML/JSON gets verbose fast, which is why many teams author with the CDK instead
  • Default deployments wait for every resource to stabilize, which is slow during iteration (express mode trades that away, with rollback off by default)
  • Git sync is limited to 17 Regions, and some features (IaC generator, drift-aware change sets) cover a subset of resource types

Best For

AWS-only teams who want AWS to hold state, roll back failures and deploy across many accounts with StackSets, especially if they author in the AWS CDK.

State: a file you guard versus a stack AWS keeps

This is the real dividing line. Terraform stores what it manages in terraform.tfstate, a JSON file mapping every resource address in your code to a real object ID. By default it sits next to your code, and HashiCorp's own docs tell you to move it to HCP Terraform or a remote backend and not to commit it to version control, because the file can contain secrets. On AWS the usual answer is the S3 backend. Its locking used to need a DynamoDB table; the current docs mark DynamoDB locking as deprecated and offer use_lockfile = true instead, which writes a .tflock object next to the state (and needs s3:GetObject, PutObject and DeleteObject on it). Locking is automatic once configured, and terraform force-unlock exists for the day a CI job dies mid-apply. CloudFormation has none of this. The stack is the state, AWS serializes operations on it, and nobody can download it by accident. The trade is control: with Terraform you can move, split and repair state with terraform state commands and moved blocks; with CloudFormation you work through the service's own tools (resource import, stack refactoring across up to five stacks, force delete for stuck stacks). Ephemeral resources and write-only arguments reduce what lands in state, but only for attributes providers have implemented.

What happens when a deployment fails

CloudFormation's default is all or nothing. The CloudFormation FAQ describes 'automatic rollback on error' as enabled by default: if any resource in the operation fails, the stack returns to its last known stable configuration. You still pay for resources created during a failed attempt. For debugging, the 'preserve successfully provisioned resources' option keeps what succeeded so you can fix the template and retry without recreating everything. Terraform has no rollback. If an apply creates nine resources and the tenth fails, the nine stay, the state records them, and the next plan shows only what is left to do. Many teams prefer this fix-forward model because a rollback can be as disruptive as the failure; others want the guarantee that production is never left half-changed. Speed is the other side. CloudFormation waits for each resource to stabilize by default, for example an EC2 instance reaching running. The newer express mode, set with --deployment-config '{"mode":"EXPRESS"}', reports completion once the API call succeeds, turns rollback off unless you set disableRollback to false, propagates to nested stacks, and is not supported for StackSets. AWS positions it for development loops, not production. Terraform's apply speed depends on the provider; it creates independent resources in parallel and waits as long as each provider's resource implementation does.

Drift, import and generating code from what already exists

Both tools now handle the 'someone clicked in the console' problem, but differently. CloudFormation's drift detection compares a stack's expected property values with live values and marks resources and stacks as drifted, and it works on StackSets too. Drift-aware change sets go further: a three-way comparison of the live state, the last deployment and the new template, so you can see whether a deploy would silently revert an incident fix. Coverage is 'hundreds of resource types', with a fallback to the classic two-way comparison for the rest. In Terraform, any terraform plan refreshes state and shows drift as a diff; scheduled drift detection and continuous validation are HCP Terraform health assessments, documented as Standard and Premium edition features. For adoption, Terraform's import blocks put the import into a reviewed plan, and plan -generate-config-out writes the HCL for you; bulk import works through queries that discover unmanaged resources. CloudFormation's IaC generator scans a whole Region (or chosen resource types, since March 2025), keeps the scan for 30 days, and turns selected resources into a template or a CDK app; auto-import and manual import then attach them to a stack. Expect to clean up generated code either way, and test imports in a sandbox account first.

Scale limits, multi-account and cost

CloudFormation's quotas are the limits teams hit first: 500 resources per template, 200 parameters, 200 outputs, 200 mappings, a 51,200-byte template body inline or 1 MB from S3, 60 dynamic references per template, and 2,500 resources per nested-stack operation. The usual answer is nested stacks or splitting by lifecycle, and stack refactoring now lets you split an oversized stack without recreating resources. The Terraform CLI has no equivalent caps; the practical limit is how long a refresh of thousands of resources takes, which is why 1.17 added -minimal-refresh and why teams split state per component anyway. HCP Terraform Stacks do have caps: 20 deployments, 100 components and 10,000 resources per Stack. For many accounts, StackSets are CloudFormation's strongest feature: one template, service-managed permissions through AWS Organizations, up to 100,000 stack instances per stack set and automatic deployment to new accounts. Terraform needs a provider alias per account and region, or a wrapper. Cost: CloudFormation is free for AWS resources; third-party resource types and custom Hooks are $0.0009 per handler operation after 1,000 free per month (AWS's own example: 500 third-party resources touched daily comes to $12.60). Terraform's CLI is free; HCP Terraform is free for small teams and paid beyond five users, but HashiCorp's pricing pages returned HTTP 429 to us, so we quote no prices.

Worked example: validating the same S3 bucket in both tools

We wrote the same versioned S3 bucket twice and ran each tool's validation on 16 November 2026. Terraform 1.17.2 (checksum verified against HashiCorp's SHA256SUMS) with an S3 backend using use_lockfile = true: terraform fmt -check passed, but terraform validate stopped with 'Error: Missing required provider. This configuration requires provider registry.terraform.io/hashicorp/aws, but that provider isn't available... terraform init'. Validation needs the provider schema, so CI must run terraform init with registry access, a provider mirror or a plugin cache before it can lint. For CloudFormation we added a deliberate typo, VersioningEnabled: true, next to the correct VersioningConfiguration. cfn-lint 1.60.1 ran offline with no AWS credentials and returned exit code 6 with two findings: 'E3002 Additional properties are not allowed ('VersioningEnabled' was unexpected)' at line 10, and 'W3011 Both 'UpdateReplacePolicy' and 'DeletionPolicy' are needed to protect resource from deletion', because we had set DeletionPolicy: Retain alone. The takeaway is practical: CloudFormation linting is a pip install away and catches property typos before any API call, while Terraform linting is precise but depends on fetching providers first. Neither replaces a real plan or change set against the target account.

Verdict

Pick CloudFormation when everything you manage lives in AWS and you would rather AWS own state, locking and rollback than run that plumbing yourself. That covers most AWS-only product teams, and especially organizations with many accounts, where StackSets and Hooks give a platform team a supported way to push baselines and guardrails into every account. If raw YAML is the objection, author with the AWS CDK: you get TypeScript, Python, Java, C#, Go or JavaScript and still deploy through CloudFormation. Pick Terraform when your infrastructure is not only AWS: GitHub repos, Datadog monitors, Splunk, Kubernetes and Helm releases and a second cloud all fit in the same plan, and that single reviewed diff is the main reason teams choose it. Terraform is also the better fit when you want unit-tested modules (terraform test with mocks) and fast plan/apply loops in your own CI. Accept the cost that comes with it: a remote state backend with locking, a plan for secrets in state, and fix-forward instead of rollback. If the Business Source License is a problem for you, read our OpenTofu vs Terraform comparison before committing. Our default: CloudFormation plus CDK for AWS-only teams, Terraform for multi-provider estates.

All Comparisons

Terraform vs AWS CloudFormation — FAQ

Common questions answered from the comparison above

Is Terraform better than CloudFormation for AWS?

Not by default. For an AWS-only estate CloudFormation gives you managed state, automatic rollback, built-in drift detection and StackSets at no extra cost for AWS resources. Terraform is better when you also manage non-AWS systems, want one language across them, or want faster plan/apply loops and native module tests. Many AWS-only teams who dislike YAML choose the AWS CDK, which still deploys through CloudFormation.

Does CloudFormation cost money?

There is no additional charge for resources in the AWS::*, Alexa::* and Custom::* namespaces; you pay for the AWS resources the stack creates. Third-party resource types and custom Hooks are billed per handler operation: $0.0009 per operation after a free tier of 1,000 operations per month per account, plus $0.00008 per second for any operation running longer than 30 seconds (prices read on 16 November 2026).

Where should I store Terraform state on AWS?

In a remote backend with locking, not in Git. The S3 backend is the common choice: set use_lockfile = true so Terraform writes a .tflock object next to the state. DynamoDB-based locking still works but is marked deprecated in the backend docs and will be removed in a future minor version. Restrict access to the bucket, because state can contain secrets. HCP Terraform is the hosted alternative.

Can CloudFormation manage resources outside AWS?

Only through the CloudFormation registry: you activate third-party public extensions or register private resource types, and those are billed per handler operation. For broad multi-provider coverage (DNS providers, SaaS, other clouds) Terraform's provider ecosystem, roughly 7,760 providers in the registry API, is far larger.

Can I move from CloudFormation to Terraform without recreating resources?

Yes. Write Terraform import blocks for the resources (or let terraform plan -generate-config-out draft the HCL), apply the import, and then remove the resources from the CloudFormation stack with DeletionPolicy: Retain so deleting the stack does not delete them. Test the sequence in a non-production account first; the reverse direction works with CloudFormation resource import or the IaC generator.

Is Terraform still open source?

Terraform 1.6.0 and later are released under the Business Source License 1.1, with IBM as licensor. Production use is allowed unless you offer Terraform to third parties as a competing hosted or embedded product. It is source-available, not OSI open source. OpenTofu is the community fork under an open-source licence; see our OpenTofu vs Terraform page.

Get the next comparison by email

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.