Terraform · Infrastructure as code

How does Terraform compare with CloudFormation?

MediumcloudformationawstoolingUpdated Oct 2026
Quiz this track

Short answer

Terraform is multi-cloud, uses HCL and keeps its own state. CloudFormation is AWS-native, uses YAML or JSON, and tracks stacks inside AWS. Choose by cloud scope, team skills and ecosystem fit.

Both tools are declarative and both compute a change set from a desired template. The difference is ownership. Terraform is an external tool with a provider plugin model and its own state. CloudFormation is an AWS service that stores stack state and performs changes inside your account.

  • Scope: Terraform covers AWS, Azure, GCP and SaaS APIs; CloudFormation is AWS-only
  • Language: HCL versus YAML or JSON templates
  • State: Terraform state lives in a backend you operate; CloudFormation stack state lives in AWS
  • Drift: both detect it, but CloudFormation drift detection is per stack and not automatic
  • Extensibility: Terraform providers and modules versus CloudFormation registry and CDK
hcl
resource "aws_s3_bucket" "logs" {
  bucket = "acme-logs-prod"
}
The Terraform equivalent of an AWS::S3::Bucket stack resource. HCL stays compact as resources grow.

CloudFormation is compelling when an organisation is AWS-only, wants native stack rollback and service-managed permissions, or depends on features such as StackSets for multi-account rollout. Terraform is usually stronger when one workflow must cover several clouds, when the team already has HCL modules, or when provider coverage matters more than native AWS integration.

AWS CDK is another option: it synthesises CloudFormation from a general-purpose language. It improves authoring but keeps the CloudFormation deployment model and its AWS-only scope.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Which tool would you choose for a multi-cloud estate?
  2. 2How does state management differ between the two?
  3. 3What are the limits of CloudFormation drift detection?
  4. 4Where does AWS CDK fit into this comparison?

Say it in the interview

Terraform is a multi-cloud declarative tool with HCL and its own state, while CloudFormation is AWS-native and keeps stack state inside AWS. I would choose CloudFormation for an AWS-only shop that values native rollback and StackSets, and Terraform when one workflow has to cover several clouds or reuse existing HCL modules. The real decision is about operational ownership and ecosystem, not which syntax looks nicer.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Terraform mock interview and get scored feedback on depth, clarity and confidence.