This repo demonstratest the usage of a cdktf construct package as source for:
- A native Terraform module
- A construct consumable in
cdktf
distributed via NPM - A native Terraform module distributed via NPM ;)
While this hybrid use-case isn't explictly supported in the Terraform CDK (cdktf
) at the moment, it's totally possible do achieve this already.
git clone git@github.com:skorfmann/cdktf-hybrid-module.git
cd cdktf-hybrid-module
yarn
yarn build
cd examples/cdktf-example
$(yarn bin)/cdktf diff
NB: The last step (cdktf diff
) expects valid AWS credentials in ENV
- Synthesize a stack without a provider und use the synthesized folder as module.
- Release the construct as part of the npm package
- As bonus, package the Terraform JSON as well, so you could use NPM as module manager
See also this blog post.
- Outputs are already fully supported by
cdktf
but due to the random naming a bit hard to use. There' an open issue to address this - Variables aren't directly supported in
cdktf
, but can still be done with escape hatches. There's an open issue - Since there aren't official prebuilt provider packages at the moment, this has to inline the generated constructs. That's the biggest drawback at the moment, but the work to improve this is underway - see this open issue.
- Add jsii for polyglot package
- Add unit tests
- Come up with a more realistic example for the construct
While it's not the best user experience at this point, I think this demonstrates that the Terraform CDK is capable of distributing hybrid modules. When the various issues around this topic are fixed, it'll be actually a pretty good user experience from my point of view.
Contributions to this repository are more than welcome!