This plugin allows integrating Terraform CDK (aka CDKTF) into your existing NX codebase. It makes it easier to manage your cloud infrastructure from the same monorepo as your application(s) codebase.
It provides:
- Project generator
- Stack generator (opinionated)
- General CDKTF executors
- Synth
- Deploy
- Destroy
- Provider
- Add
- Get
- List
- Upgrade
Note: This plugin is just a wrapper for CDKTF for Typescript, therefore this documentation does not include any CDKTF specific instructions.
For this plugin to work properly you need to have the CDKTF CLI set up locally. Follow the official Getting Started Guide (if you haven't already).
Adding the CDKTF plugin to an existing Nx workspace can be done with the following:
npm i -D nx-cdktf
It's straightforward to setup your application:
nx g nx-cdktf:init appName
By default, the application will be configured with:
- NX Configuration and main.ts file
- A set of targets and executors to invoke common CDKTF commands to manage your application. You can add more executors later.
We can then call the following commands:
# executors
nx synth appName
nx deploy appName
nx destroy appName
nx run appName:add-provider google
nx run appName:get-providers
nx run appName:list-providers
nx run appName:upgrade-provider google
# generators
nx g nx-cdktf:stack CloudRun --project appName
Tip: You can change the location or rename your cdktf.out folder, but it's best to leave it in the project root so you can run other CDKTF commands from the project folder.
Here is a list of all the executors and generators available from this package:
- synth: Synthesizes Terraform code for the given app in a directory.
- deploy: Deploy the given stacks
- destroy: Destroy the given stacks
- init: Setup a new CDKTF Project