how to write cdktf module instead terraform module

1.5k Views Asked by At

Instead of referring terraform module in cdktf i want to refer CDKTF typescript files to combine several resources as one. How can i achieve this?

Below is for terraform module but expecting something like this for cdktf

"terraformModules": [   
{
"name": "my-local-module",
"source": "./New folder"
}
],
2

There are 2 best solutions below

3
Daniel Schmidt On

You can use import {myExport} from "./path-to-ts-file"; and export myExport = ... in the file you are exporting from. You can see an example for this in the serverless typescript demo: https://github.com/hashicorp/cdktf-integration-serverless-example/blob/main/main.ts#L5 & https://github.com/hashicorp/cdktf-integration-serverless-example/blob/main/posts/index.ts#L13

3
javierlga On

You need to import the Terraform module, then run cdktf get and finally import it, e.g.:

import { MyLocalModule } from "./.gen/modules/my-local-module";