Project stack (main.ts)
The application stack initializes the local provider, sets a base project directory, and instantiates a reusable construct that creates the project folder and files.- What this does: adds the local provider and creates a
ProjectFolderconstruct forproject-1under./authors-projects. - Why this helps: defining resources via constructs keeps your infrastructure code modular and reusable.
Reusable construct: ProjectFolder
TheProjectFolder construct encapsulates file creation using the local provider. It demonstrates how to expose created resources (e.g., readMeFile) and how to provide typed props for clarity and autocompletion.
- The construct pattern makes it easy to reuse folder/file creation across multiple projects.
- Exposing resource references (like
readMeFile) allows other constructs or stacks to consume outputs if needed.
Application entrypoint
After defining constructs and stacks, create the app and synthesize the Terraform configuration:
What we covered
- Adding and using providers and resources in CDKTF.
- Encapsulating related resources using constructs for better organization and reuse.
- Exposing outputs and checking them to verify created resources.
- Synthesizing CDKTF code to Terraform configuration for validation and deployment.

Practical recommendations and best practices
- Break constructs into logical units and pass outputs as required between constructs or stacks for larger deployments.
- When managing files, decide whether to create
.gitignoreand other files inside the construct or manage them independently—both approaches are valid depending on your workflow.
Run
yarn cdktf synth frequently during development to validate your CDKTF code quickly.Final notes
This example is intentionally small—creating local folders and files could be done with a shell script—but it demonstrates the CDKTF fundamentals: providers, resources, constructs, type-safe props, and synthesis. These fundamentals scale to more complex, cloud-based infrastructure automation where the benefits of type safety, reusability, and testability become even more valuable. Further reading and references:- CDK for Terraform (CDKTF) docs: https://developer.hashicorp.com/terraform/cdktf
- Terraform documentation: https://www.terraform.io/docs
- Constructs programming model: https://github.com/aws/constructs