Skip to main content
Welcome to the CDKTF introduction module. This guide explains what CDKTF is, the prerequisites and tooling you need, and how to initialize a minimal TypeScript CDKTF project. We’ll follow a practical example — Arthur’s journey — to automate repetitive local project scaffolding using Terraform’s local provider. This local example is a compact, hands-on way to introduce CDKTF concepts before applying them to cloud providers like AWS. CDKTF (Cloud Development Kit for Terraform) lets you define and provision infrastructure using familiar programming languages (TypeScript, Python, Go, etc.) while taking advantage of Terraform’s provider ecosystem and state management. It combines Terraform’s declarative model with the expressiveness of general-purpose languages and constructs.
A developer icon points to a panel with two buttons labeled "Define" and "Provision." Below the panel are logos for TypeScript, Python, Go, and Terraform.
We assume you have a basic working knowledge of TypeScript. This lesson shows how to use that knowledge with CDKTF to provision resources locally (files) via Terraform’s local provider, and prepares you to extend the same patterns to cloud providers later. Overview
  • Define the problem CDKTF will solve.
  • Review prerequisites and essential tools.
  • Initialize a TypeScript CDKTF project from scratch.
  • Introduce the cdktf CLI and synth/deploy workflow.
Arthur’s problem Arthur frequently creates new projects and repeatedly types the same boilerplate files (for example .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):
A dark-themed Visual Studio Code window with the Explorer sidebar on the left, a right-click context menu open, and the integrated terminal visible along the bottom. The editor area is mostly empty with a large faint icon in the center.
Typical files Arthur creates:
  • .gitignore
  • README.md
  • package.json (for Node/TypeScript projects)
Example boilerplate files package.json
README.md
The idea: automate this repetitive work with CDKTF so Arthur can generate the same files consistently across projects. Exploring CDKTF Define Terraform resources using programming languages you already know, synthesize them into Terraform configuration, and apply via Terraform.
A presentation slide titled "Exploring CDKTF" showing the AWS Cloud Development Kit logo paired with the HashiCorp Terraform logo and the caption: "Allows you to define Terraform resources using familiar programming languages."
Arthur chooses TypeScript because he is already familiar with it.
A presentation slide titled "Author's Decision" listing two choices. It shows using CDKTF to automate project setups and using TypeScript (with corresponding icons).
Prerequisites and tools Before you start, install the tools listed below. These are the minimums required to run CDKTF with TypeScript.
A presentation slide titled "Install Node.js" showing bullet points to "Install Homebrew" and "Install node" with a link to the Node.js download page. The slide shows a KodeKloud copyright at the bottom.
Install Terraform (example on macOS using Homebrew)
Install the CDKTF CLI globally (optional)
If you prefer not to install a global CLI (recommended for CI reproducibility), add 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.
Initialize a new TypeScript CDKTF project
  1. Create an empty directory and open a terminal there.
  2. (Optional) Install the cdktf CLI globally or add it as a dev dependency.
  3. Run the CDKTF init wizard to scaffold a TypeScript project.
Quick start
Sample init prompts (abbreviated)
The init command scaffolds a TypeScript project (tsconfig, package.json, main.ts) and installs provider packages such as @cdktf/provider-local. Console logs may show provider installation:
Generated package.json (dependencies snippet)
Switch package manager to Yarn (optional) If you prefer Yarn (and Yarn 2+/Corepack-managed installs), prepare and activate it with Corepack, then migrate the lockfile.
A presentation slide titled "Change Package Manager to Yarn (Optional)" that states the problem "npm is slow and does not have modern tooling." Below it is a black rounded callout/button reading "Delete package-lock.json."
Add the CLI as a project dev dependency (recommended for CI)
With a local 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).
Example main.ts with a Terraform output
Notes on constructs
  • scope builds the construct tree and creates parent-child relationships.
  • id uniquely identifies a construct within its parent.
  • app.synth() converts your TypeScript code into .tf.json Terraform configuration; it does not apply changes to infrastructure.
cdktf.json cdktf init generates a cdktf.json file with metadata and the app command used to run your CDKTF application:
Set the 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:
Synthesis output appears in cdktf.out/stacks/<stack-name> and includes Terraform JSON and metadata. Example synth output:
Deploy (synth + terraform apply)
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 state For this example we used local state; Terraform will create a local state file (e.g., 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)
Summary
  • 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 init to scaffold a TypeScript project, and how the synth/deploy workflow maps to Terraform JSON and terraform apply.
  • Optional items covered: switching package managers (Yarn) and installing cdktf-cli locally 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.

Watch Video

Practice Lab