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.
Previous
How does Terraform handle dependencies between resources?
Next
What are advanced Terraform state management operations?
More Terraform / IaC Questions
View all →- Advanced What is Terraform's provider development and custom providers?
- Advanced What is Policy as Code with Sentinel in Terraform?
- Advanced How does Terraform handle dependencies between resources?
- Advanced What are advanced Terraform state management operations?
- Advanced How do you implement a CI/CD pipeline for Terraform?