{"id":16961,"library":"cdktf-cli","title":"CDK for Terraform CLI","description":"CDK for Terraform (cdktf-cli) provides a command-line interface for developing and deploying Terraform configurations using familiar programming languages like TypeScript, Python, Go, C#, and Java. It allows developers to define infrastructure as code using object-oriented principles and high-level abstractions, which are then synthesized into Terraform HCL. The current stable version is 0.21.0, with frequent patch and minor releases occurring roughly every 1-2 weeks, indicating active development and a rapid release cadence. This approach differentiates it from writing raw HCL by enabling programmatic control, reusability of components through custom constructs, and leveraging existing language ecosystems for comprehensive testing, static analysis, and integrated development tooling. It aims to bridge the gap between traditional software development paradigms and the provisioning of cloud infrastructure.","status":"active","version":"0.21.0","language":"javascript","source_language":"en","source_url":"git://github.com/hashicorp/terraform-cdk","tags":["javascript","cdk","cdktf","terraform"],"install":[{"cmd":"npm install cdktf-cli","lang":"bash","label":"npm"},{"cmd":"yarn add cdktf-cli","lang":"bash","label":"yarn"},{"cmd":"pnpm add cdktf-cli","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"cdktf-cli is a command-line interface and is not designed for programmatic import into a Node.js application. Interact with it via shell commands using `npx cdktf` for ephemeral execution, or install globally with `npm install -g cdktf-cli` to use `cdktf` directly.","wrong":"import { cdktf } from 'cdktf-cli';","symbol":"cdktf","correct":"npx cdktf init --template=\"typescript\" --local"},{"note":"For project-specific CLI usage, define scripts in your `package.json` to leverage the locally installed `cdktf-cli` binary from `node_modules/.bin` without requiring global installation.","symbol":"package.json script","correct":"{\n  \"scripts\": {\n    \"deploy\": \"cdktf deploy\",\n    \"synth\": \"cdktf synth\"\n  }\n}"}],"quickstart":{"code":"// First, initialize a new CDKTF project (run these commands in your terminal):\n// mkdir my-cdktf-project\n// cd my-cdktf-project\n// npx cdktf init --template=\"typescript\" --local --project-name=\"my-s3-app\" --stack-name=\"dev\"\n//\n// When prompted, select 'typescript' as the language and choose an example like AWS S3 bucket.\n//\n// After initialization, modify the generated 'main.ts' file (e.g., in 'main.ts' or 'src/main.ts')\n// to define an S3 bucket. You might need to install the AWS provider: 'npm i @cdktf/provider-aws'\n\nimport { Construct } from 'constructs';\nimport { App, TerraformStack, TerraformOutput } from 'cdktf';\nimport { AwsProvider } from '@cdktf/provider-aws/lib/provider';\nimport { S3Bucket } from '@cdktf/provider-aws/lib/s3-bucket';\n\nclass MyS3Stack extends TerraformStack {\n  constructor(scope: Construct, id: string) {\n    super(scope, id);\n\n    new AwsProvider(this, 'aws', {\n      region: 'us-east-1',\n    });\n\n    const bucket = new S3Bucket(this, 'my-unique-cdktf-bucket', {\n      bucket: `my-cdktf-example-bucket-${Math.random().toString(36).substring(2, 7)}`,\n      acl: 'private',\n      tags: {\n        Environment: 'Development',\n        ManagedBy: 'CDKTF',\n      },\n    });\n\n    new TerraformOutput(this, 'bucket_name', {\n      value: bucket.bucket,\n      description: 'The name of the S3 bucket created by CDKTF.',\n    });\n  }\n}\n\nconst app = new App();\nnew MyS3Stack(app, 'my-s3-stack');\napp.synth();\n\n// To deploy this infrastructure, navigate to your project root in the terminal and run:\n// npx cdktf deploy\n//\n// To destroy the deployed resources:\n// npx cdktf destroy\n","lang":"typescript","description":"This quickstart demonstrates how to initialize a new CDKTF project, define an AWS S3 bucket using TypeScript, and then deploy and destroy the infrastructure using the `cdktf` CLI commands."},"warnings":[{"fix":"Upgrade your Node.js environment to version 20.9 or higher. Use a version manager like `nvm` (`nvm install 20 && nvm use 20`) or download the latest LTS release from nodejs.org.","message":"The minimum required Node.js version has been updated to 20.9. Running `cdktf-cli` v0.21.0 or newer with older Node.js versions will result in an error.","severity":"breaking","affected_versions":">=0.21.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Upgrade Node.js to version 20.9 or higher. Use `nvm install 20 && nvm use 20` or install directly from nodejs.org.","cause":"Attempting to run `cdktf-cli` v0.21.0 or newer with an unsupported Node.js version (e.g., Node.js 18).","error":"Error: The installed Node.js version (v18.x.x) is not supported. Please upgrade to Node.js 20.9 or later."},{"fix":"Ensure you are in the project root directory, verify the stack name matches the one defined in your code (e.g., `new MyS3Stack(app, 'my-s3-stack')`), and confirm that `cdktf synth` has been run to generate the Terraform configuration files.","cause":"The `cdktf deploy` or `cdktf destroy` command was run with an incorrect stack ID, from the wrong directory, or before `cdktf synth` was executed successfully.","error":"Error: No stack found with ID 'my-s3-app'."}],"ecosystem":"npm","meta_description":null}