CLI Commands
Note: CDK for Terraform is currently in beta.
The CDK for Terraform CLI has the following commands:
completion
This command outputs a script that you can use to set up autocompletion for bash or zsh.
The output also contains the installation instructions. For example, here are the instructions for Mac OSX:
After you configure auto completion, reload your shell by running source ~/.zshrc
, source ~/.bash_profile
or opening a new terminal window. You can now autocomplete cdktf
commands by pressing the <TAB>
key. You may need to enter a space after cdktf
for autocomplete to take effect.
convert
This command converts Terraform configuration written in HCL to the equivalent configuration in your preferred language.
->Note: The convert
command is only functional for Terraform 1.0 and above. There are also known limitations.
Examples
Convert a local file.
Convert HCL in your clipboard to Python on OSX.
Convert HCL in your clipboard to Python on OSX.
deploy
This command deploys a given application.
Help Output
Examples
Deploy an application.
Deploy an application with automatic approval of the diff (Terraform plan).
destroy
This command destroys a given application.
Help output:
Examples
Destroy an application.
Destroy an application with automatic approval of the diff (Terraform plan).
diff
This command generates a diff for a given application by running Terraform plan.
Help output:
Examples:
Generate a diff for a given application.
get
This command downloads the providers and modules for an application and
generates CDK constructs for them. It can use the cdktf.json
configuration file to read the list of providers and modules.
Help Output
Examples
Download the providers and modules defined in the cdktf.json
configuration file.
init
This command creates a new CDK for Terraform project using a template.
Help Output
Examples
Create a new Typescript project.
Create a new Python project and use a specific version of the cdktf
package.
Create a new Typescript project from an existing Terraform codebase. Currently, you can only use the --from-terraform-project
flag with TypeScript, and there are some known limitations.
login
This command helps log in to Terraform Cloud by fetching a Terraform Cloud API token.
Help Output
Examples
Fetch an API token from Terraform Cloud.
synth
This command synthesizes Terraform configuration for an application. CDKTF stores the synthesized configuration in the cdktf.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
.
Help Output
Examples
Synthesize code for an application.
Synthesize code when providing a custom command to execute and an output directory.
Synthesize code for an application and output the Terraform JSON configuration.
watch
Warning: The watch
command is experimental, so you should only use it in development environments. It also automatically deploys all changes without asking for confirmation.
The watch
command watches a directory for changes and automatically synthesizes and deploys changes as they happen. It allows for rapid iterations when developing infrastructure, especially when working with serverless services. It currently supports only one stack at a time and automatically deploys changes without asking for confirmation.
Watch reads your root .gitignore
file to determine which files trigger a synth
and it uses the outdir
of your cdktf.json
(or the default cdktf.out
) to do so for a deploy. It will generate a checksum of the subdirectory containing the Terraform code for your stack to skip deploys if the synthesized Terraform config did not change.
Requirements
Before using watch
you should:
Check your root
.gitignore
file. Your root.gitignore
must contain all files that are generated bysynth
anddeploy
. If that is not the case, thewatch
command will trigger itself and continuously try to deploy. Although Git supports nesting.gitignore
files, thewatch
command currently only reads the root.gitignore
file.Check your environment. The
watch
command should only be used for development environments. We recommend making sure that the terminal where you want to runwatch
has no access keys that allow thecdktf-cli
to deploy to your production environment.
Run watch
Help Output
Examples
Run watch
on the development stack (dev). The --auto-approve
flag skips the explicit plan approval step and is currently always required.
Troubleshoot watch
Set the CDKTF_LOG_LEVEL
environment variable to all
and set CDKTF_DISABLE_LOGGING
to false
.
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.