# AWS CDK vs Terraform

AWS comparisons · Updated 17 November 2026

**Short answer:** Choose the AWS CDK when your team are developers who want to define AWS infrastructure in TypeScript, Python, Java, C# or Go, with high-level constructs that wire up IAM and networking for you, and you are happy for CloudFormation to deploy it. Choose Terraform when you manage several clouds or SaaS providers, prefer declarative HCL that operations teams read easily, or need one tool for everything.

## CDK vs Terraform compared

| Factor | AWS CDK | Terraform |
|---|---|---|
| Language | TypeScript, JavaScript, Python, Java, C#/.NET, Go | HCL |
| Abstraction | L1 (raw CloudFormation), L2 (sensible defaults), L3 patterns | Resources and modules |
| Deployment engine | Synthesises CloudFormation templates and deploys stacks | Terraform core calls provider APIs directly |
| State | CloudFormation stacks | State file you store and lock |
| Rollback | CloudFormation automatic rollback | No automatic rollback |
| Preview | `cdk diff` (and change sets) | `terraform plan` |
| Providers | AWS (third-party through CloudFormation registry) | AWS and many others |
| Setup | Bootstrap each account and Region (S3 bucket, ECR repository, IAM roles) | Backend for state (for example S3 with locking) |

## When the CDK is the better choice

- Application teams who already write TypeScript or Python and want infrastructure in the same repository, tested with the same tools.
- You want L2 constructs that generate least-privilege IAM grants (`bucket.grantRead(fn)`) and sane defaults instead of writing every property.
- Repeated patterns across many services, packaged as your own construct library.
- You want CloudFormation's managed state and rollback without writing YAML.

## When Terraform is the better choice

- Your estate spans AWS plus other clouds or SaaS (DNS, CDN, monitoring, source control).
- Platform or operations teams who want readable, declarative configuration rather than a program that generates it.
- You need fine control over individual resources and imports without CloudFormation's quotas and stack boundaries.

Be explicit about state: store it remotely with locking and encryption, restrict who can read it, and plan how you will split it as the estate grows.

## Migrating or mixing

CDK and Terraform can coexist in one organisation as long as each resource has one owner. To bring existing CloudFormation templates into the CDK, use `CfnInclude`; to generate a CDK app from deployed resources, the CDK Migrate feature (in preview) builds on CloudFormation's IaC generator. Moving from CDK to Terraform means retaining resources in CloudFormation, removing them from the stack and importing them into Terraform.

## Common wrong reasons

- **"CDK avoids CloudFormation limits."** It deploys CloudFormation, so stack quotas and update behaviour still apply.
- **"Terraform cannot be tested."** It has a built-in test framework and plan-based policy checks; CDK has assertions on synthesised templates.
- **"Code is always better than config."** Loops and conditionals help, but clever infrastructure code is harder to review during an incident.

## Questions

### Is AWS CDK better than Terraform?

For AWS-only teams of developers who want typed code and high-level constructs, often yes. For multi-provider estates or teams that prefer declarative configuration, Terraform is usually the better fit.

### Does the CDK use CloudFormation?

Yes. The CDK synthesises CloudFormation templates and deploys them as stacks, so CloudFormation handles state and rollback.

### Do I need to bootstrap for CDK?

Yes. Each account and Region must be bootstrapped once, which creates an S3 bucket, an ECR repository and IAM roles used for deployments.

## When this happens away from your desk

When an infrastructure deploy breaks production, you want the failing resource and the change that triggered it, not the whole pipeline log. CloudConsole is being built to show deploy events and alarms on a phone with production guardrails.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [What is the AWS CDK?](https://docs.aws.amazon.com/cdk/v2/guide/home.html)
- [AWS CDK constructs](https://docs.aws.amazon.com/cdk/v2/guide/constructs.html)
- [Terraform (AWS Prescriptive Guidance)](https://docs.aws.amazon.com/prescriptive-guidance/latest/choose-iac-tool/terraform.html)

## Related

- [CloudFormation vs Terraform](https://cloudconsole.dev/vs/cloudformation-vs-terraform)
- [AWS CDK vs CloudFormation](https://cloudconsole.dev/vs/cdk-vs-cloudformation)
- [Requires capabilities: [CAPABILITY_IAM]](https://cloudconsole.dev/errors/cloudformation-requires-capabilities)
- [Resource already exists in stack](https://cloudconsole.dev/errors/cloudformation-resource-already-exists)
- [aws cloudformation describe-stack-events](https://cloudconsole.dev/cli/cloudformation-describe-stack-events)
- [ALB vs API Gateway](https://cloudconsole.dev/vs/alb-vs-api-gateway)

---

Source: https://cloudconsole.dev/vs/cdk-vs-terraform

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
