HCL is purpose-built for infrastructure. CDKTF lets you use general-purpose languages instead. Both produce Terraform plans. The question is which tradeoffs fit your team.
What CDKTF Is
The Cloud Development Kit for Terraform (CDKTF) generates Terraform JSON from code written in TypeScript, Python, Go, Java, or C#:
// main.ts
import { App, TerraformStack } from "cdktf";
import { AwsProvider } from "@cdktf/provider-aws/lib/provider";
import { Instance } from "@cdktf/provider-aws/lib/instance";
import { Vpc } from "@cdktf/provider-aws/lib/vpc";
class MyStack extends TerraformStack {
constructor(scope: App, id: string) {
super(scope, id);
new AwsProvider(this, "aws", { region: "eu-west-1" });
const vpc = new Vpc(this, "vpc", {
cidrBlock: "10.0.0.0/16",
tags: { Name: "production" },
});
new Instance(this, "web", {
ami: "ami-0c55b159cbfafe1f0",
instanceType: "t3.medium",
subnetId: vpc.id,
});
}
}
const app = new App();
new MyStack(app, "production");
app.synth();Run cdktf synth and it generates standard Terraform JSON. Then cdktf deploy applies it.
Master this topic with hands-on labs
Go beyond reading — build real projects in sandboxed environments with expert video guidance.
Browse Courses →HCL Equivalent
provider "aws" {
region = "eu-west-1"
}
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = { Name = "production" }
}
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.medium"
subnet_id = aws_vpc.main.id
}For simple infrastructure, HCL is more concise and readable.
Where CDKTF Wins
Complex Logic
HCL has for_each, count, dynamic blocks, and locals — but they are limited compared to real programming constructs:
// CDKTF: Generate resources programmatically
const environments = ["dev", "staging", "production"];
const instanceSizes: Record<string, string> = {
dev: "t3.small",
staging: "t3.medium",
production: "t3.large",
};
for (const env of environments) {
new Instance(this, `web-${env}`, {
ami: "ami-0c55b159cbfafe1f0",
instanceType: instanceSizes[env],
tags: { Environment: env },
});
}Loops, conditionals, and data transformations are natural in TypeScript. In HCL, the equivalent requires nested for_each expressions that are harder to read and debug.
Type Safety
CDKTF has full type checking. Your IDE catches errors before you run terraform plan:
// TypeScript catches this at compile time
new Instance(this, "web", {
ami: "ami-0c55b159cbfafe1f0",
instanceType: "t3.mediummm", // Type error: not a valid instance type
});Shared Libraries
Package infrastructure patterns as npm/PyPI packages:
// Reusable module as a TypeScript class
export class StandardVpc extends Construct {
public readonly vpc: Vpc;
public readonly publicSubnets: Subnet[];
constructor(scope: Construct, id: string, props: VpcProps) {
super(scope, id);
// Standard VPC configuration
}
}Teams import and use it like any library dependency. Versioning, changelogs, and breaking change detection come from the language ecosystem.
Get weekly IT automation tips
Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.
Subscribe Free →Where HCL Wins
Readability for Infrastructure
HCL was designed to be readable by people who are not programmers. A resource block is self-documenting:
resource "aws_s3_bucket" "logs" {
bucket = "my-app-logs"
}The CDKTF equivalent requires understanding classes, constructors, and object-oriented patterns.
Community Ecosystem
99% of Terraform modules on the registry are HCL. Examples, tutorials, and Stack Overflow answers are HCL. Using CDKTF means translating constantly.
Plan Readability
terraform plan output maps directly to HCL resource blocks. With CDKTF, the plan references generated resource names that are harder to trace back to source code.
Simpler Mental Model
HCL is declarative: "this is what I want." CDKTF is imperative: "this is how to build what I want." Declarative is easier to reason about for infrastructure state.
Decision Guide
Choose HCL if: - Your team includes non-programmers (SREs, sysadmins) - Infrastructure is straightforward (standard cloud resources) - You want maximum community support and examples - Simplicity matters more than flexibility
Choose CDKTF if: - Your team is developer-heavy (TypeScript/Python is their primary language) - You need complex logic, loops, and abstractions - You want to share infrastructure patterns as packages - Type safety is important for your workflow
---
Ready to go deeper? Master Terraform from scratch with our hands-on course at CopyPasteLearn.
Ready to learn by doing?
Stop reading tutorials — start building. Expert video courses with hands-on labs in real sandboxed environments.
Related Articles
Ansible vs Terraform When to Use
Ansible and Terraform solve different infrastructure problems. Learn when to use each, when to use both together, and how they complement each other.
Pulumi Infrastructure as Code Guide
Pulumi lets you write infrastructure in TypeScript, Python, Go, or C# with full programming language features. Learn how Pulumi works, how it compares.
Terragrunt DRY Terraform Guide
Terragrunt eliminates copy-paste in multi-environment Terraform setups. Learn how to use Terragrunt for DRY configuration, remote state management.
Terraform CI/CD Pipelines
Build CI/CD pipelines for Terraform using GitHub Actions. Automate plan, apply, and destroy workflows with safety checks.
Terraform Course: What You Learn
What a Terraform course teaches you. Skills, exercises, AWS provisioning, and career benefits of learning Terraform for IaC.
Terraform Expert Tips and Patterns
Level up Terraform skills with expert patterns. Dynamic blocks, for_each, moved blocks, validation, and production workflows.
Explore topics
Browse more articles on the topics covered here.