What is the Terraform CDK (CDKTF)?

Answer

The Cloud Development Kit for Terraform (CDKTF) allows defining Terraform infrastructure using general-purpose programming languages instead of HCL. Supported languages: TypeScript, Python, Java, C#, Go. CDKTF generates HCL JSON that Terraform can apply. Example in TypeScript: import { App, TerraformStack } from "cdktf"; import { AwsProvider, instance } from "@cdktf/provider-aws"; class MyStack extends TerraformStack { constructor(scope, id) { super(scope, id); new AwsProvider(this, "AWS", { region: "us-east-1" }); new instance.Instance(this, "Compute", { ami: "ami-0c55b159cbfafe1f0", instanceType: "t3.micro" }) } }. Benefits: use programming language constructs (loops, conditions, classes) instead of HCL's limited expressions; IDE type-checking; leverage existing package ecosystems. Downsides: adds complexity and requires familiarity with the language. CDKTF is gaining adoption in teams already using TypeScript or Python extensively who find HCL limiting for complex dynamic infrastructure.