- completion
- convert
- debug
- deploy
- destroy
- diff
- get
- init
- login
- output
- provider add
- provider upgrade
- provider list
- synth
- watch
completion
This command outputs a script that you can use to set up autocompletion for bash or zsh.source ~/.zshrc, source ~/.bash_profile or opening a new terminal window. You can now autocomplete cdktn commands by pressing the <TAB> key. You may need to enter a space after cdktn for autocomplete to take effect.
convert
This command converts Terraform configuration written in HCL to the equivalent configuration in your preferred language.The
convert command has known limitations.cdktn.TerraformStack instead of a cdktn.Construct.
deploy
This command deploys a given application.The
parallelism flag has a different behavior than the terraform parallelism flag. To set the custom terraform parallelism flag, please use the --terraform-parallelism flag instead.If your
cdktf.json sets validateInstalledBinary: true, deploy verifies the installed Terraform or OpenTofu binary satisfies your declared targetVersions before applying, and errors if it does not.-production in one run:
myStack.addDependency(otherStack)) deploy will figure out the right order to run.
For more info on the --outputs-file option, refer to the output command.
destroy
This command destroys a given application.The
parallelism flag has a different behavior than the terraform parallelism flag. To set the custom terraform parallelism flag, please use the --terraform-parallelism flag instead.If your
cdktf.json sets validateInstalledBinary: true, destroy verifies the installed Terraform or OpenTofu binary satisfies your declared targetVersions before running, and errors if it does not.myStack.addDependency(otherStack)) deploy will figure out the right order to run.
diff
This command generates a diff for a given application by running Terraform plan.The
parallelism flag has a different behavior than the terraform parallelism flag. To set the custom terraform parallelism flag, please use the --terraform-parallelism flag instead.If your
cdktf.json sets validateInstalledBinary: true, diff verifies the installed Terraform or OpenTofu binary satisfies your declared targetVersions before running the plan, and errors if it does not.get
This command downloads the providers and modules for an application and generates CDK constructs for them. It can use thecdktf.json configuration file to read the list of providers and modules.
This command only generates currently missing provider bindings, so it is very fast if nothing changed.
The command does not update the version when you specify loose version constraints in your cdktf.json file and have already generated an existing version locally. To update the version anyway, run cdktn get --force to recreate all bindings.
When you change a version constraint, the cdktn get command recreates the bindings for that provider.
cdktf.json configuration file.
--parallelism option to limit the number of bindings generated in parallel.
init
This command creates a new CDK Terrain project using a template.cdktn package.
--from-terraform-project flag with TypeScript, and there are some known limitations.
login
This command helps log in to HCP Terraform by fetching a HCP Terraform API token.https protocol.
Examples
Fetch an API token from HCP Terraform.
synth
This command synthesizes Terraform configuration for an application. CDKTN stores the synthesized configuration in thecdktf.out directory, unless you use the --output flag to specify a different location. The output folder is ephemeral and might be erased for each synth that you run manually or that happens automatically when you run deploy, diff, or destroy.
watch
When thewatch command is first run it creates a watchPattern in your cdktf.json based on the language you configured. It’s a list of glob patterns matching all files that should be watched.
Whenever a file matching the watch pattern is changed, the command will run cdktn deploy --auto-approve for you. It allows for rapid iterations when developing infrastructure, especially when working with serverless services. You can specify the stacks you want to deploy or you can use cdktn watch --auto-approve '*' to deploy all stacks.
Requirements
Before usingwatch you should check your environment. The watch command should only be used for development environments. We recommend making sure that the terminal where you want to run watch has no access keys that allow the cdktn-cli to deploy to your production environment.
Run watch
The
parallelism flag has a different behavior than the terraform parallelism flag. To set the custom terraform parallelism flag, please use the --terraform-parallelism flag instead.watch on the development stack (dev). The --auto-approve flag skips the explicit plan approval step and is currently always required.
--auto-approve flag, you can use the same configuration options as in cdktn deploy.
Troubleshoot watch
Set theCDKTF_LOG_LEVEL environment variable to all and set CDKTF_LOG_FILE_DIRECTORY to your projects root directory.
The debug output is directed to a cdktf.log file in your projects root directory. The log contains information about detected file system changes and the actions they triggered.
The debug output is directed to a cdktf.log file in your projects root directory. The log contains information about detected file system changes and the actions they triggered.
output
This command gets the outputs defined in the Terraform configuration of the given stack. It usesterraform output under the hood.
--outputs-file
The --outputs-file option allows you to specify a file where the stack outputs will be written as JSON.
The JSONs structure is matching your construct structure, the name of each construct is used as a key.
--outputs-file-include-sensitive-outputs option is used.
debug
This command prints debug information about the current project and environment to help troubleshoot issues. Help Outputconstructs version through Gradle.
provider add
This command facilitates adding Terraform providers to a CDKTN project. If a pre-built provider is available for the CDKTN version you are using and the Terraform provider version you requested (if any), it will be installed using e.g.npm install or dotnet add depending on the language you are using. Otherwise, the provider will be added to the cdktf.json config and cdktn get will be automatically invoked to generate local provider bindings.
aws provider to the project. As the namespace of the AWS Terraform provider is hashicorp it can be left out.
aws provider to the project. You can use the @ symbol to specify a version constraint.
provider upgrade
This command lets you upgrade Terraform providers in a CDKTN project to the newest version compatible with yourcdktn version. You can also optionally add a version constraint.
If your project has the associated pre-built provider already installed, CDKTN updates the pre-built provider. Otherwise, CDKTN adds the provider to the cdktf.json configuration file and invokes cdktn get to generate local provider bindings.
provider list
This command prints out a table (or json with the--json option) containing details about the providers installed for the project. It gathers information for both locally built and pre-built providers.
Information printed varies between locally generated and prebuilt providers. The information for each provider includes the Terraform provider version, the CDKTN version, and the package name and version (if pre-built provider).
aws provider to the newest version available for your cdktn version.
aws provider to the newest version available for your cdktn version and at version 4 of the provider version.
cdktn version.