Initialize Project from a Template
Useinit with a project template to automatically create and scaffold a new CDKTN project for your chosen programming language.
Templates generate a new application with the necessary file structure for you to start defining infrastructure.
You can use a cdktn-cli pre-built template or a custom-built remote template when you initialize a new project.
typescriptpythonc#javago
Use a Local Backend
Add the--local flag to created a scaffolded project that is pre-configured to use a local backend. This means that your application stores Terraform state on your local machine and all Terraform operations run locally.
Use HCP Terraform as a Remote Backend
When you runcdktn init without the --local flag, CDKTN defaults to using HCP Terraform as a remote backend. This lets you store state and run Terraform operations remotely in HCP Terraform. Refer to Set Up CDKTN With HCP Terraform for details.
Project Configuration
Initializing your project with a template generates a basic project in your preferred programming language that you can customize for your use case. You can manage global configuration for your project by customizing thecdktf.json configuration file or the application context.
cdktf.json Configuration File
The cdktf.json configuration file is where you can define the providers and modules that should be added to the project and supply custom configuration settings for the application. Refer to the cdktf.json documentation for more detail.
Application Context
All of the classes in your application can access the applicationcontext, so it is an ideal place to store project configuration. Context becomes available to any construct in your application after you run cdktn synth.
You can configure context as a static value in cdktf.json by setting the context property.
App class.
App context to provide a custom tag value to an AWS EC2 instance.
Generate Terraform Configuration
Runcdktn synth to synthesize your application into JSON configuration files that Terraform can use to manage infrastructure. You can then either use the JSON file with Terraform directly or provision your infrastructure using CDKTN CLI commands.
Refer to Deployment Patterns for example workflows, including connecting your CDKTN application to a Continuous Integration pipeline.
Convert an HCL Project to a CDKTN TypeScript Project
You can initialize a new CDKTN TypeScript project from an existing project written in HashiCorp Configuration Language (HCL). This option is currently limited to thetypescript template.
To convert an existing HCL project, add --from-terraform-project to the init command with the TypeScript template.
Usage Example
The following HCL configuration defines therandom provider.
Convert HCL Files to CDKTN Format
Use thecdktn convert command to convert individual HCL files to CDKTN-compatible files in your preferred programming language. Refer to the cdktn convert command documentation for more information.