
- Define the problem CDKTF will solve.
- Review prerequisites and essential tools.
- Initialize a TypeScript CDKTF project from scratch.
- Introduce the
cdktfCLI and synth/deploy workflow.
.gitignore, README.md, package.json). In this module we automate generating those files locally using CDKTF + Terraform local provider. While a shell script might be the most pragmatic choice for production scaffolding, using CDKTF here teaches the core workflow and patterns you’ll reuse with cloud providers.
Meet Arthur — repetitive project setup in a code editor (example Visual Studio Code):

.gitignoreREADME.mdpackage.json(for Node/TypeScript projects)



cdktf-cli to each project as a dev dependency — CI runners will then use the local binary.
Using local Terraform state is convenient for demos and quick experiments, but it is not recommended for team or production environments. For collaborative workflows use remote state backends such as Terraform Cloud, S3 + DynamoDB locking, or other supported backends.
- Create an empty directory and open a terminal there.
- (Optional) Install the
cdktfCLI globally or add it as a dev dependency. - Run the CDKTF init wizard to scaffold a TypeScript project.
main.ts) and installs provider packages such as @cdktf/provider-local.
Console logs may show provider installation:

cdktf binary, scripts like yarn cdktf synth or npm run synth will use the project’s executable, improving consistency across environments.
Project structure and main TypeScript file
After cdktf init, the scaffold contains a main.ts (or main.js) entrypoint and a stack class. Key concepts:
- App: the root construct that contains stacks.
- TerraformStack: extend this class to define resources.
- app.synth(): synthesizes TypeScript constructs into Terraform configuration (JSON files).
main.ts with a Terraform output
scopebuilds the construct tree and creates parent-child relationships.iduniquely identifies a construct within its parent.app.synth()converts your TypeScript code into.tf.jsonTerraform configuration; it does not apply changes to infrastructure.
cdktf init generates a cdktf.json file with metadata and the app command used to run your CDKTF application:
app value to npx ts-node main.ts or a Yarn script (e.g., yarn ts-node main.ts) depending on your workflow.
Synthesizing and deploying
Synthesize your CDKTF TypeScript into Terraform JSON files:
cdktf.out/stacks/<stack-name> and includes Terraform JSON and metadata.
Example synth output:
cdktf deploy runs app.synth() and then invokes terraform apply. In interactive mode you will be prompted to approve changes; use automation flags in CI pipelines for non-interactive runs.
Helpful package.json scripts
Add useful commands to speed development and CI:
terraform.<stack>.tfstate) when you apply. For team workflows or production, use a remote backend such as Terraform Cloud, S3 with DynamoDB locking, or other supported options.
Example state metadata (abbreviated)
- CDKTF allows you to author Terraform-managed infrastructure using TypeScript (and other languages), combining Terraform providers with familiar programming constructs.
- We covered prerequisites, how to run
cdktf initto scaffold a TypeScript project, and how the synth/deploy workflow maps to Terraform JSON andterraform apply. - Optional items covered: switching package managers (Yarn) and installing
cdktf-clilocally for reproducible CI. - Next: continue Arthur’s journey by implementing the local file generation stack and then applying these same patterns to cloud infrastructure such as AWS.