Skip to main content

Configuration File

tfts uses a configuration file named cdktf.json (or tfts.json) to manage project settings, providers, and modules.

Schema

The following fields are supported in the configuration file:
FieldTypeDescription
languagestringMust be set to "typescript". (Required)
appstringThe command to run your application (e.g., "bun run main.ts" or "node main.js").
outputstringThe directory where synthesized Terraform JSON will be stored. Default: "cdktf.out".
codeMakerOutputstringThe directory where generated provider bindings will be stored. Default: ".gen".
terraformProvidersstring[]An array of provider specifications (e.g., "hashicorp/aws@~> 5.0").
terraformModulesstring[]An array of module sources to generate bindings for.
contextobjectOptional key-value pairs for context variables.

Example Configuration

cdktf.json
{
  "language": "typescript",
  "app": "bun run main.ts",
  "terraformProviders": [
    "hashicorp/aws@~> 5.0",
    "hashicorp/google@~> 6.0"
  ],
  "terraformModules": [
    "terraform-aws-modules/vpc/aws"
  ],
  "output": "dist",
  "codeMakerOutput": "src/gen"
}

Environment Variables

You can override certain configuration settings using environment variables:
  • CDKTF_OUTDIR: Overrides the output directory setting.
  • CDKTF_CONTEXT_JSON: Provides context variables as a JSON string.

Advanced Examples

Using Context Variables

You can define context variables in your configuration file and access them in your code.
cdktf.json
{
  "language": "typescript",
  "app": "bun run main.ts",
  "context": {
    "environment": "production",
    "region": "us-west-2"
  }
}

Custom Output Directories

If you want to separate your generated bindings from your source code:
cdktf.json
{
  "language": "typescript",
  "app": "bun run main.ts",
  "codeMakerOutput": ".generated-bindings",
  "output": "terraform.out"
}