AWS CDK vs Terraform
AWS CDK defines AWS infrastructure in real programming languages with high-level constructs and CloudFormation-managed state, but is AWS-centric. Terraform is declarative HCL with the largest multi-cloud ecosystem and self-managed state. Choose by cloud scope and code versus config preference.
Overview
The AWS Cloud Development Kit (CDK) and Terraform are both infrastructure-as-code tools, but they target different scopes and styles. The CDK lets you define AWS infrastructure in general-purpose programming languages, which synthesize into CloudFormation templates. Terraform uses a declarative language, HCL, and provisions resources across many clouds and providers. The choice weighs programming-language power and AWS depth against declarative portability.
Key Differences
The CDK appeals to developers who want to write infrastructure in TypeScript, Python, Java, C#, or Go. It offers high-level constructs that encapsulate best practices and dramatically reduce boilerplate; a single construct can provision a well-configured set of resources. Because the CDK compiles to CloudFormation, AWS manages deployment state and rollbacks through stacks, removing a class of operational concerns. The trade-off is scope: the CDK is AWS-centric, and its capabilities are bounded by what CloudFormation supports.
Terraform is declarative and cloud-agnostic. HCL describes desired state, and Terraform computes and applies a plan. Its greatest strength is breadth: the largest provider and module registry in IaC, spanning AWS, Azure, GCP, and hundreds of other services, which makes it the standard for multi-cloud and third-party resources. Terraform manages its own state in a backend you choose, and it offers a constrained but readable configuration model rather than full programming constructs.
In short, the CDK trades portability for developer-language power and managed state within AWS, while Terraform trades some abstraction for unmatched multi-cloud reach and ecosystem.
When to Choose AWS CDK
Choose the CDK when you are committed to AWS and want to define infrastructure in a real programming language with types, loops, and IDE support. Its high-level constructs accelerate development and encode best practices, and CloudFormation-managed state and rollbacks simplify operations for AWS-only teams.
When to Choose Terraform
Choose Terraform when you operate across multiple clouds or rely on non-AWS providers, or when you want the largest module ecosystem and a portable, declarative tool. Its breadth and ubiquity make it the safer default for heterogeneous environments and for avoiding provider lock-in.
Verdict
The CDK is excellent for AWS-centric teams that prefer programming over configuration and want managed state via CloudFormation. Terraform is the stronger choice for multi-cloud, ecosystem breadth, and a declarative approach. Some teams combine them or use the CDK for Terraform (CDKTF) to get language power with Terraform's providers. Decide based on cloud scope and whether you prefer code or declarative configuration.