AWS CDK vs Terraform: Which IaC Tool?
AWS CDK defines AWS infrastructure in real programming languages and synthesizes CloudFormation; Terraform uses declarative HCL across many providers and clouds.
CDK lets you author AWS infrastructure in TypeScript, Python, or other languages, using loops, abstractions, and constructs, then synthesizes CloudFormation under the hood, deeply AWS-native. Terraform uses declarative HCL with a vast provider ecosystem spanning AWS, GCP, Azure, and SaaS, with its own state model. CDK favors language-native AWS authoring; Terraform favors multi-cloud declarative breadth.
| AWS CDK | Terraform | |
|---|---|---|
| Style | Imperative (real code) | Declarative (HCL) |
| Scope | AWS (CloudFormation) | Multi-cloud + SaaS |
| Abstraction | Constructs, language features | Modules |
| State | CloudFormation-managed | Terraform state |
| Best for | AWS-only, code-first teams | Multi-cloud, declarative |
Use case and scope
CDK suits AWS-only teams who prefer real programming languages, reusable constructs, and CloudFormation-managed state. Terraform suits multi-cloud or SaaS-spanning infrastructure and teams who prefer declarative HCL with a huge provider ecosystem. CDK leans into AWS; Terraform spans providers and is cloud-agnostic.
In CI
Both run plan/diff and apply from CI using OIDC for keyless AWS auth; gate apply behind review. Either runs on managed runners, where faster runners shorten synth/plan and apply steps.
The verdict
AWS-only and preferring real programming languages and constructs: AWS CDK. Multi-cloud, SaaS-spanning, or declarative-HCL preference: Terraform. CDK is excellent for code-first AWS shops; Terraform is the broader, cloud-agnostic choice.