Is this import behavior expected?


so I am using normal Terraform providers with CDKTF and TS.

I am using cdktf get to generate the TS type definitions. The TS gets successfully rendered to .gen. In the documentation, it looks like we can still import from @cdktf ..... However, I was only able to get it to work by importing (in my case) relatively, like this import { AwsProvider } from "../../../../.gen/providers/aws/provider".

is it the expected behavior and the documentation is misleading? Or is something messed up with my TF config?

To answer my own q it looks like this behavior is expected. I ended up setting a path alias @providers in tsconfig.json. You can then refer to providers by using @providers/aws and so on.

However, for it to work with ts-node you also need to configure:

  "ts-node": {
    "require": ["tsconfig-paths/register"]

In tsconfig.json (and install tsconfig-paths, i.e. tsconfig-paths - npm)

Hi @johannes-gehrs :wave:

It seems like our docs are a bit misleading there since the example snippets use the pre-built providers (e.g. @cdktf/provider-aws) to speed up builds – in this section about locally built provider bindings it does confuse though.

That’s right. I’ve signed a CLA and could do a PR

I find the answer “you need to use relative imports” to be a bit lacking though, and setting an alias is non-trivial cause you need the extra package. It might be something worth thinking about more deeply from the product side.