CDK for Terraform CLI
$ npm install -g cdktf-cli
$ cdktf --help
Help output:
cdktf [command]
Commands:
cdktf deploy [OPTIONS] Deploy the given stack
cdktf destroy [OPTIONS] Destroy the given stack
cdktf diff [OPTIONS] Perform a diff (terraform plan) for the given stack
cdktf get [OPTIONS] Generate CDK Constructs for Terraform providers and modules.
cdktf init [OPTIONS] Create a new cdktf project from a template.
cdktf login Retrieves an API token to connect to Terraform Cloud.
cdktf synth [OPTIONS] Synthesizes Terraform code for the given app in a directory. [aliases: synthesize]
Options:
--version Show version number [boolean]
--disable-logging Dont write log files. Supported using the env CDKTF_DISABLE_LOGGING. [boolean] [default: true]
--log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string]
-h, --help Show help [boolean]
Options can be specified via environment variables with the "CDKTF_" prefix (e.g. "CDKTF_OUTPUT")
If running in automated environments, the dynamic CLI output rendering can be forced to be static with the CI
enviornment variable set to a trueish value.
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.
$ cdktf get --help
Help output:
cdktf get [OPTIONS]
Generate CDK Constructs for Terraform providers and modules.
Options:
--version Show version number [boolean]
--disable-logging Dont write log files. Supported using the env CDKTF_DISABLE_LOGGING. [boolean] [default: true]
--log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string]
--output, -o Output directory for generated Constructs [string] [default: ".gen"]
--language, -l Output programming language [string] [required] [choices: "typescript", "python", "java", "csharp", "go"]
-h, --help Show help [boolean]
Examples:
Download providers and modules defined in the cdktf.json
configuration file.
$ cat cdktf.json
{
"language": "typescript",
"app": "node main.js",
"terraformProviders": ["aws@~> 2.0"]
}
$ cdktf get
This command creates a new CDK for Terraform project using a template.
$ cdktf init --help
Help output:
cdktf init [OPTIONS]
Create a new cdktf project from a template.
Options:
--version Show version number [boolean]
--disable-logging Dont write log files. Supported using the env CDKTF_DISABLE_LOGGING. [boolean] [default: true]
--log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string]
--template The template name to be used to create a new project. [string] [choices: "python", "typescript", "java", "csharp", "go"]
--project-name The name of the project. [string]
--project-description The description of the project. [string]
--dist Install dependencies from a "dist" directory (for development) [string]
--local Use local remote state storage for generated Terraform. [boolean] [default: false]
--cdktf-version The cdktf version to use while creating a new project. [string] [default: "0.0.0"]
-h, --help Show help [boolean]
Examples:
Create a new Typescript project.
$ cdktf init --template="typescript"
Create a new Python project and use a specific version of the cdktf
package.
$ cdktf init --template="python" --cdktf-version="0.0.1"
This command synthesizes Terraform configuration for an application.
$ cdktf synth --help
Help output:
cdktf synth [OPTIONS]
Synthesizes Terraform code for the given app in a directory.
Options:
--version Show version number [boolean]
--disable-logging Dont write log files. Supported using the env CDKTF_DISABLE_LOGGING. [boolean] [default: true]
--log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string]
--app, -a Command to use in order to execute cdktf app
--output, -o Output directory [default: "cdktf.out"]
--json Provide JSON output for the generated Terraform configuration. [boolean] [default: false]
-h, --help Show help [boolean]
Examples:
Synthesize code for a given application.
$ cdktf synth
Synthesize code when providing a custom command to execute and an output directory.
$ cdktf synth --app="npm compile && node main.js" --output="dirname"
Synthesize code for a given application and output the Terraform JSON configuration.
$ cdktf synth --json
This command generates a diff for a given application by running Terraform plan.
$ cdktf diff --help
Help output:
cdktf diff [OPTIONS]
Perform a diff (terraform plan) for the given stack
Options:
--version Show version number [boolean]
--disable-logging Dont write log files. Supported using the env CDKTF_DISABLE_LOGGING. [boolean] [default: true]
--log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string]
--app, -a Command to use in order to execute cdktf app [required]
--output, -o Output directory [required] [default: "cdktf.out"]
-h, --help Show help [boolean]
Examples:
Generate a diff for a given application.
$ cdktf diff
This command deploys a given application.
$ cdktf deploy --help
Help output:
cdktf deploy [OPTIONS]
Deploy the given stack
Options:
--version Show version number [boolean]
--disable-logging Dont write log files. Supported using the env CDKTF_DISABLE_LOGGING. [boolean] [default: true]
--log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string]
--app, -a Command to use in order to execute cdktf app [required]
--output, -o Output directory [required] [default: "cdktf.out"]
--auto-approve Auto approve [boolean] [default: false]
-h, --help Show help [boolean]
Examples:
Deploy a given application.
$ cdktf deploy
Deploy a given application with auto approval of the diff (Terraform plan).
$ cdktf deploy --auto-approve
This command destroys a given application.
$ cdktf destroy --help
Help output:
cdktf destroy [OPTIONS]
Destroy the given stack
Options:
--version Show version number [boolean]
--disable-logging Dont write log files. Supported using the env CDKTF_DISABLE_LOGGING. [boolean] [default: true]
--log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string]
--app, -a Command to use in order to execute cdktf app [required]
--output, -o Output directory [required] [default: "cdktf.out"]
--auto-approve Auto approve [boolean] [default: false]
-h, --help Show help [boolean]
Examples:
Destroy a given application.
$ cdktf destroy
Destroy a given application with auto approval of the diff (Terraform plan).
$ cdktf destroy --auto-approve
This command helps login to Terraform Cloud by fetching a Terraform Cloud API token.
$ cdktf login --help
Help output:
cdktf login
Retrieves an API token to connect to Terraform Cloud.
Options:
--version Show version number [boolean]
--disable-logging Dont write log files. Supported using the env CDKTF_DISABLE_LOGGING. [boolean] [default: true]
--log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string]
-h, --help Show help [boolean]
Examples:
Fetch an API token from Terraform Cloud.
$ cdktf login