Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

CloudFormation vs Terraform

By Kokil Thapa | Last reviewed: September 2026

You need repeatable infrastructure, not another late-night console session. The CloudFormation vs Terraform debate sits at the centre of that decision for teams shipping on AWS, and often beyond it. Both tools turn servers, networks, and databases into versioned code. They differ sharply in scope, state handling, and day-two operations. This guide compares them the way a production engineer would—using real templates, real trade-offs, and the constraints small teams in Nepal and worldwide actually face. If you are new to IaC, start with our practical Terraform infrastructure-as-code guide for baseline concepts that apply to both tools.

What is the difference between CloudFormation and Terraform?

Both tools implement infrastructure as code (IaC). You declare desired resources in files, commit them to Git, and apply changes through automation. The execution model and ecosystem diverge from there.

AWS CloudFormation is a first-party AWS service. You write YAML or JSON templates. CloudFormation creates a stack—a living record of every resource in that deployment. AWS stores stack state internally. You never manage a state file yourself.

Terraform is an open-source tool from HashiCorp (with the OpenTofu fork as an alternative). You write HCL configuration. Terraform calls provider APIs directly. It maintains a state file that maps your config to real resource IDs. That state is your responsibility—or your platform team's.

CloudFormation vs Terraform — Core ArchitectureAWS CloudFormationYAML / JSON templatesStack = managed stateAWS APIs onlyHashiCorp TerraformHCL configurationExternal state file100+ cloud providersShared goal: declarative, versioned infrastructureGit commit → review → automated apply → audit trailCF: zero state ops · TF: full state control + multi-cloudPick based on cloud scope and team maturity
CloudFormation vs Terraform — AWS-native stacks compared with Terraform's provider-driven model and external state

A minimal CloudFormation template defines an S3 bucket:

AWSTemplateFormatVersion: '2010-09-09'
Description: Static assets bucket
Resources:
  AssetsBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketEncryption:
        ServerSideEncryptionConfiguration:
          - ServerSideEncryptionByDefault:
              SSEAlgorithm: AES256
Outputs:
  BucketName:
    Value: !Ref AssetsBucket

The Terraform equivalent uses the AWS provider:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

resource "aws_s3_bucket" "assets" {
  bucket = "my-app-assets-prod"
}

resource "aws_s3_bucket_server_side_encryption_configuration" "assets" {
  bucket = aws_s3_bucket.assets.id
  rule {
    apply_server_side_encryption_by_default {
      sse_algorithm = "AES256"
    }
  }
}

CloudFormation syntax is verbose. Terraform HCL reads cleaner for most developers. CloudFormation wins on zero setup inside AWS. Terraform wins when the same patterns must run on multiple clouds. For AWS-only fundamentals, see our AWS CloudFormation fundamentals walkthrough.

When should you choose AWS CloudFormation over Terraform?

CloudFormation is the right default when your entire footprint lives on AWS and you want the simplest operational surface.

AWS-only shops with no multi-cloud plans

If every resource—VPC, RDS, Lambda, CloudFront—sits in AWS accounts you control, CloudFormation removes an entire class of problems. There is no remote state bucket to secure. No state lock table to monitor. No risk of a corrupted local terraform.tfstate file leaking into Git.

AWS also ships same-day support for new services. When AWS launches a feature, CloudFormation resource types often follow within weeks. Terraform provider coverage lags by days or months depending on community demand.

Teams already deep in the AWS console

CloudFormation integrates natively with CloudWatch, StackSets, Service Catalog, and IAM. Drift detection runs from the console or CLI without third-party tooling. Stack policies can block destructive updates on production resources—a built-in guardrail Terraform handles through external policy engines like Sentinel or Checkov.

Regulated environments favouring vendor-managed state

Some compliance frameworks treat vendor-managed infrastructure records favourably. CloudFormation stacks are authoritative AWS objects with CloudTrail audit logs. You do not maintain a separate state artifact that could desync from reality.

On a production Laravel deployment I maintain, the application runs on EC2 behind an ALB with RDS MySQL. The underlying AWS networking could be CloudFormation-managed without touching application code. That separation keeps Linux server administration and IaC concerns in distinct layers—a pattern that scales well for client projects with small ops teams.

How does state management compare in CloudFormation vs Terraform?

State is the sharpest practical difference between the two tools. Get it wrong and you get duplicate resources, orphaned volumes, or failed applies.

CloudFormation: stacks as living state

When you run aws cloudformation create-stack, AWS records every resource ID inside the stack. Updates are diffed against that record. Deletes remove tracked resources—unless you added retention policies.

Drift detection compares the live stack against the last deployed template. AWS documents this workflow in the CloudFormation resource management guide. Importing existing resources into a stack is supported, though the process is more rigid than Terraform import.

Terraform: explicit state you must protect

Terraform writes resource mappings to a state file—JSON that links aws_s3_bucket.assets to arn:aws:s3:::my-app-assets-prod. Local state works for solo experiments. Production teams use remote backends.

A typical S3 backend with DynamoDB locking looks like this:

terraform {
  backend "s3" {
    bucket         = "company-terraform-state"
    key            = "prod/network/terraform.tfstate"
    region         = "ap-southeast-1"
    dynamodb_table = "terraform-locks"
    encrypt        = true
  }
}

State locking prevents two engineers from applying simultaneously. Encryption protects sensitive outputs. Our guides on managing Terraform state safely and remote state on S3 with locking cover the full setup.

IaC Deploy Workflow ComparisonCloudFormationTerraformWrite templatecreate-stack / updateAWS manages stateStack events in consoleterraform initterraform planterraform applyState file updatedTF plan step gives explicit diff preview — CF relies on change sets
CloudFormation stack deploy cycle versus Terraform init-plan-apply workflow with explicit state updates

CloudFormation change sets provide a preview similar to terraform plan. They are less readable for complex templates but serve the same gatekeeping purpose in CI pipelines.

Drift: both tools detect it, neither auto-heals silently

Manual console edits create drift. CloudFormation drift detection flags resources that differ from the template. Terraform plan shows differences on the next run. Neither tool silently reverts manual changes—you must apply intentionally. See Terraform drift detection strategies for Terraform-specific patterns.

Which tool is better for multi-cloud infrastructure in 2026?

Terraform wins multi-cloud by design. One HCL codebase can provision AWS EC2, Cloudflare DNS, and a PostgreSQL 18 instance on a VPS—all in one apply graph.

CloudFormation cannot leave AWS. If you need Azure or GCP resources, you add a second tool anyway. That hybrid reality pushes many teams toward Terraform from the start.

CriteriaAWS CloudFormationTerraform
Cloud scopeAWS onlyAWS, Azure, GCP, Cloudflare, 100+ providers
State managementAWS-managed stacksSelf-managed (local or remote backend)
LanguageYAML / JSONHCL (JSON serialisation supported)
Module ecosystemAWS::CloudFormation::Stack nested stacks, Serverless transformsRegistry modules, local modules, Terragrunt wrappers
Plan previewChange setsterraform plan with colour diff
CostFree (pay for resources created)Free OSS; Terraform Cloud/Enterprise paid tiers
New AWS service supportFastest (first-party)Depends on provider release cycle
Policy enforcementStack policies, IAM, Service CatalogOPA, Sentinel, Checkov, native check blocks
Learning curveModerate; verbose syntaxModerate; state concepts add complexity
Best fitAWS-only, minimal ops overheadMulti-cloud, hybrid, or provider-agnostic teams

For teams evaluating beyond these two, our Terraform vs Pulumi vs OpenTofu comparison covers the broader IaC landscape. OpenTofu matters in 2026 because it preserves the Terraform workflow under a truly open licence after HashiCorp's BSL change.

CloudFormation vs Terraform Decision TreeAll infra on AWS only?YesNoPrefer zero state ops?Need multi-cloudYesNoCloudFormationAWS-native stacksTerraformState + modulesTerraformOne workflow, many providersSmall team on AWS? CF reduces moving parts.Growing platform team? TF modules scale better.
Decision tree for CloudFormation vs Terraform based on cloud scope and operational preferences

Reusable modules matter at scale. CloudFormation nested stacks work but feel clunky compared to Terraform modules published on the public registry. Our Terraform modules guide shows patterns you can port conceptually to nested stacks. Terragrunt adds DRY layering on top—see keeping Terraform DRY with Terragrunt.

On booking platforms like Adventure Third Pole Trek, infrastructure spans application servers, CDN, and managed databases. Terraform often provisions that base layer while Laravel handles business logic—a clean split that enterprise application development teams replicate across client projects.

How do you run CloudFormation and Terraform in CI/CD pipelines?

IaC without CI/CD is just expensive documentation. Both tools fit Git-based workflows, but the pipeline steps differ.

CloudFormation in CI/CD

A typical GitLab or GitHub Actions pipeline validates the template, creates a change set, waits for human approval on production, then executes the change set.

  1. Run cfn-lint against the template for syntax and best-practice checks.
  2. Upload the template to S3 if it exceeds the inline size limit.
  3. Call aws cloudformation create-change-set against the target stack.
  4. Review the change set output in the pipeline log or Slack notification.
  5. Execute with aws cloudformation execute-change-set after approval.

StackSets extend this to multi-account AWS Organisation deployments—a native feature Terraform lacks without custom wrappers.

Terraform in CI/CD

Standard pipeline stages: init, validate, plan, apply. Store plans as artefacts. Require approval before apply on production workspaces.

terraform init -backend-config=backends/prod.hcl
terraform validate
terraform plan -out=plan.tfplan
terraform apply -auto-approve plan.tfplan

Never run apply without a saved plan in production. Plan files pin the exact diff that apply will execute. Our Terraform CI/CD with GitHub Actions article walks through a complete example. Scan plans with Checkov for Terraform misconfigurations before merge.

Real-World Deployment PatternsCloudFormation StackVPC + RDS + ALB + EC2Single AWS accountDeployer 7 target hostTerraform Multi-ProviderAWS EC2 + Cloudflare DNS+ monitoring SaaSOne state, one pipelineLaravel app on EC2 — infra separate from PHP codeGitLab CI builds assets · IaC provisions serversGotcha: mixing manual console edits with either tool causes driftTreat the console as read-only after IaC adoption
AWS-only CloudFormation stacks versus multi-provider Terraform deployments for production web applications

I've maintained sister legal-tech sites on a shared Deployer 7 pipeline. The EC2 hosts could be CloudFormation-provisioned while Deployer handles zero-downtime Laravel releases. That two-layer model—infra tool plus deploy tool—is common on projects documented in our CloudFormation on AWS guide.

Policy, cost, and testing

Both ecosystems support policy-as-code. CloudFormation Guard (cfn-guard) validates templates against rules. Terraform integrates with Checkov, tfsec, and native check blocks in recent versions. Run policy checks in CI before any apply reaches production.

Cost estimation differs. Infracost parses Terraform plans and estimates monthly spend. CloudFormation has no direct equivalent—teams use AWS Cost Explorer after deployment or third-party scanners. For budget-sensitive Nepal startups, that preview step alone can justify Terraform on AWS-only projects.

Testing matters too. Use task validate or cfn-lint for CloudFormation. Use terraform validate plus tools like Terratest for Terraform. Validate JSON outputs in pipelines with our JSON formatter when debugging state or plan artefacts.

Ongoing ops—patching, backup verification, certificate renewal—still need human process regardless of IaC choice. Our support and maintenance services cover the application layer that IaC does not replace.

Key Takeaways

  • Choose CloudFormation for AWS-only footprints where you want zero state file management and fastest new-service support.
  • Choose Terraform when you need multi-cloud, hybrid providers, or a richer module ecosystem with explicit plan diffs.
  • Protect Terraform state with remote backends, encryption, and DynamoDB locking—never commit state to Git.
  • Run both tools through CI/CD with lint, plan/change-set preview, approval gates, and policy scans before production apply.
  • Treat the AWS console as read-only after IaC adoption—manual edits cause drift in both tools.
  • Separate infrastructure provisioning from application deployment; IaC builds the platform, Deployer or similar tools ship the code.

People Also Ask

Can you use CloudFormation and Terraform together?

Yes. A common pattern provisions base networking with CloudFormation and manages application-specific resources with Terraform—or the reverse. Avoid managing the same resource in both tools. Pick one owner per resource to prevent state conflicts and duplicate provisioning.

Is CloudFormation going away?

No. AWS continues investing in CloudFormation, including CDK—which synthesises to CloudFormation templates. CloudFormation remains the underlying engine for most AWS-native IaC approaches. Terraform coexists rather than replaces it for AWS-only teams who prefer managed stacks.

Which is easier to learn for beginners?

CloudFormation has fewer concepts—no state backends, no provider pinning. Terraform reads more naturally thanks to HCL syntax and has a larger tutorial ecosystem. Beginners on AWS-only projects often start with CloudFormation. Developers who already know HCL from other tools pick up Terraform faster.

Does Terraform cost money?

Terraform CLI is free and open source. HashiCorp charges for Terraform Cloud team features, drift detection, and policy sets. CloudFormation itself is free—you pay only for the AWS resources stacks create. Budget at least Rs 0 for the tools; budget for the EC2, RDS, and data transfer they provision.

Pick the right IaC tool and ship with confidence

The CloudFormation vs Terraform choice is not about which tool is "better" in abstract terms. It is about cloud scope, team size, and how much operational control you want over state. AWS-only teams with minimal DevOps headcount should start with CloudFormation. Everyone else—multi-cloud, hybrid DNS, SaaS integrations—should standardise on Terraform or OpenTofu and invest in remote state from day one.

Either path beats manual console clicking. Wire IaC into your Git pipeline, enforce policy checks, and keep infrastructure changes as reviewable as application code. If you want help designing a deployment stack for a Laravel, WordPress, or custom application on AWS or VPS infrastructure, contact us to discuss architecture that matches your team and budget. For zero-downtime update patterns once infra is live, read our guide on zero-downtime infrastructure updates and explore hosting options via domain registration and hosting in Nepal.

Frequently Asked Questions

Both implement infrastructure as code: you declare resources in files, commit to Git, and apply through automation. CloudFormation is AWS-native—you write YAML or JSON templates, AWS creates a stack, and stores state internally with no state file to manage. Terraform is open source from HashiCorp, uses HCL, calls provider APIs directly, and maintains an explicit state file mapping config to real resource IDs. CloudFormation syntax is more verbose; Terraform HCL reads cleaner. CloudFormation wins on zero setup inside AWS; Terraform wins when the same patterns must run across multiple clouds.

Choose CloudFormation when your entire footprint lives on AWS and you want the simplest operational surface. AWS-only shops avoid remote state buckets, lock tables, and corrupted local state files leaking into Git. AWS ships same-day support for new services—CloudFormation resource types often follow within weeks, while Terraform provider coverage lags. Teams deep in the AWS console benefit from native CloudWatch, StackSets, Service Catalog, and IAM integration. Stack policies block destructive updates without third-party policy engines. Regulated environments may favour vendor-managed stack records with CloudTrail audit logs instead of a separate state artifact you maintain yourself.

State is the sharpest practical difference. CloudFormation records every resource ID inside the stack when you create or update it; AWS diffs updates against that record and supports drift detection against the last deployed template. Terraform writes mappings to a JSON state file linking config names to real ARNs. Solo work can use local state; production teams use remote backends—typically S3 with DynamoDB locking, encryption enabled—to prevent concurrent applies and protect sensitive outputs. Get state wrong in either tool and you risk duplicate resources, orphaned volumes, or failed applies. Never commit Terraform state to Git.

Terraform wins multi-cloud by design. One HCL codebase can provision AWS EC2, Cloudflare DNS, and a PostgreSQL instance on a VPS—all in one apply graph. CloudFormation cannot leave AWS; Azure or GCP resources require a second tool anyway. That hybrid reality pushes many teams toward Terraform from the start. Terraform also offers a richer public module registry compared to CloudFormation nested stacks, which work but feel clunkier at scale. For AWS-only footprints with no multi-cloud plans, CloudFormation remains the simpler choice. OpenTofu preserves the Terraform workflow under a truly open licence if licensing matters to your team.

Yes, and teams do it regularly. A common pattern provisions base networking with CloudFormation while Terraform manages application-specific resources—or the reverse. On production Laravel deployments, EC2 behind an ALB with RDS MySQL might sit on CloudFormation-managed networking while application code ships separately through Deployer. The critical rule: never manage the same resource in both tools. Pick one owner per resource to prevent state conflicts, duplicate provisioning, and orphaned infrastructure. Treat infrastructure provisioning and application deployment as distinct layers—IaC builds the platform; deploy tools ship the code.

No. AWS continues investing in CloudFormation, including CDK, which synthesises to CloudFormation templates. CloudFormation remains the underlying engine for most AWS-native IaC approaches and coexists with Terraform rather than being replaced by it.

CloudFormation has fewer concepts—no state backends, no provider pinning, no init-plan-apply workflow to internalise. Its YAML and JSON syntax is verbose, which slows reading but keeps the mental model small. Terraform reads more naturally thanks to HCL and has a larger tutorial ecosystem, but state management adds real complexity early. Beginners on AWS-only projects often start with CloudFormation. Developers who already know HCL from other HashiCorp tools pick up Terraform faster. Both have a moderate learning curve; the choice depends more on cloud scope than absolute difficulty.

Terraform CLI is free and open source. HashiCorp charges for Terraform Cloud team features, drift detection, and policy sets. CloudFormation is free; you pay only for provisioned AWS resources.

IaC without CI/CD is expensive documentation. CloudFormation pipelines typically run cfn-lint for syntax checks, upload large templates to S3, create a change set, require human approval on production, then execute the change set. StackSets extend this to multi-account AWS Organisation deployments—a native feature Terraform lacks without custom wrappers. Terraform pipelines follow init, validate, plan, and apply stages. Store plan files as artefacts and require approval before production apply—never run apply without a saved plan. Scan Terraform plans with Checkov before merge. Both tools fit GitLab CI and GitHub Actions workflows with lint, preview, approval gates, and policy scans.

Manual console edits create drift in both tools, and neither silently reverts changes—you must apply intentionally to realign infrastructure. CloudFormation drift detection compares the live stack against the last deployed template, runnable from the console or CLI without third-party tooling. Terraform plan shows differences on the next run. CloudFormation change sets provide a preview similar to terraform plan—less readable on complex templates but serving the same gatekeeping purpose in CI. After IaC adoption, treat the AWS console as read-only. Drift flags problems; fixing them requires a deliberate template or config update plus apply.

Both ecosystems support policy-as-code in CI before production apply. CloudFormation Guard validates templates against rules; stack policies block destructive updates on production resources—a built-in guardrail. Terraform integrates with Checkov, tfsec, OPA, Sentinel, and native check blocks. Protect Terraform state with remote S3 backends, encryption, and DynamoDB locking—state can contain sensitive outputs and must never land in Git. CloudFormation stacks are authoritative AWS objects audited through CloudTrail, which some regulated environments prefer over self-managed state artifacts that could desync from reality.

Cost preview differs sharply between the tools. Infracost parses Terraform plans and estimates monthly spend—a preview step that alone can justify Terraform even on AWS-only projects for budget-sensitive Nepal startups. CloudFormation has no direct equivalent; teams rely on AWS Cost Explorer after deployment or third-party scanners. Both tools are free at the CLI level—you budget for the EC2, RDS, and data transfer they provision, not the IaC layer itself. Run cost estimation in CI alongside policy scans so expensive surprises surface before approval gates, not after stacks go live.

Reusable modules matter at scale. CloudFormation uses nested stacks and Serverless transforms, but the pattern feels clunkier than Terraform modules published on the public registry. Terragrunt adds DRY layering on top of Terraform for teams managing many environments. Conceptually, patterns from Terraform modules can inform nested stack design even if you stay on CloudFormation. On booking platforms spanning application servers, CDN, and managed databases, Terraform often provisions the base layer while Laravel handles business logic—a clean split enterprise teams replicate across client projects. Pick the module ecosystem that matches your cloud scope and team size.

OpenTofu matters in 2026 because it preserves the Terraform workflow under a truly open licence after HashiCorp's BSL change. If your team evaluates the broader IaC landscape beyond CloudFormation and Terraform, OpenTofu offers a fork-compatible path without abandoning HCL, provider models, or existing module patterns. It does not change the CloudFormation vs Terraform decision for AWS-only teams—CloudFormation remains AWS-native with managed stacks. For teams already committed to the Terraform execution model but concerned about licensing, OpenTofu is the practical alternative worth comparing alongside Pulumi and other IaC tools.

The choice is not about abstract superiority—it is cloud scope, team size, and how much operational control you want over state. AWS-only teams with minimal DevOps headcount should start with CloudFormation: no state bucket to secure, fastest new AWS service support, and native StackSets for multi-account work. Choose Terraform when you need multi-cloud, hybrid providers like Cloudflare alongside AWS, richer plan diffs, or Infracost previews before spend commits. Protect Terraform state properly if you go that route. Separate IaC from application deployment—I've maintained sister legal-tech sites where CloudFormation could provision EC2 hosts while Deployer 7 handles zero-downtime Laravel releases on a shared pipeline.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: