README.md, package.json, and .gitignore using the local provider.

Quick checklist before you begin
- Initialize a CDKTF TypeScript project (
cdktf init --template="typescript"), then run:yarnto install dependenciesyarn cdktf synthto verify synthesisyarn cdktf deployto apply changes
Minimal stack to verify compilation and synth
Start with a tiny stack that produces a Terraform output to confirm your CDKTF toolchain is working:Add the local provider dependency
To use local file resources you must install the provider package:Install
@cdktf/provider-local so CDKTF can synthesize the corresponding Terraform provider block and the local_file resources.Create local files using the local provider
The@cdktf/provider-local package exposes a LocalProvider and file.File resource (maps to Terraform’s local_file). The example below:
- Initializes the local provider,
- Computes a target base path relative to the folder where you run
yarn cdktf deploy(usingprocess.env.INIT_CWDand Node’spath), - Creates
README.mdat<projectDirectory>/<projectName>/README.md.
yarn cdktf deploy, CDKTF will:
- Synthesize Terraform configuration (you’ll find generated files under
cdktf.out/), - Execute
terraform init/plan/applyto create or update the local files.
Where Terraform state is stored
By default CDKTF (like Terraform CLI) uses a local backend unless you configure a remote backend. In the synthesized output you will find a JSON backend configuration that points to a local.tfstate file. Example:
Changing file content and lifecycle behavior
- Updating the
contentof alocal_fileusually results in an in-place update (the provider updates the file’s contents). - If you want Terraform to ignore subsequent content changes (so updates in CDKTF don’t trigger applies), use the
lifecycle.ignoreChangesattribute.
Using
lifecycle.ignoreChanges prevents Terraform from reconciling the content property. Use it only when you intentionally want to decouple local file content management from Terraform updates.Changing logical IDs and adding resources
- Logical ID: the name you provide in code (for example
'readme-file') identifies the construct in the construct tree and influences the generated Terraform resource name. Renaming it (e.g., to'readme-file-2') will cause CDKTF to treat the original resource as removed and the new one as added — Terraform will plan to destroy then create. - Adding more files is as simple as adding more
file.Fileresources. UseJSON.stringifyto write formatted JSON into files likepackage.json.
package.json:
Key concepts at a glance
Recommended workflow
yarn— install dependencies including@cdktf/provider-localyarn cdktf synth— confirm the Terraform configs CDKTF will generateyarn cdktf deploy— apply changes and create files on disk- Inspect
cdktf.outto view synthesized Terraform and backend configuration
References
This concludes the section on providers and resources.