# cdktf-hybrid-module

Latest version **0.0.1** (published 2020-07-27) · MPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install cdktf-hybrid-module
pnpm add cdktf-hybrid-module
yarn add cdktf-hybrid-module
bun add cdktf-hybrid-module
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; large bundle; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2020-07-27 |
| First published | 2020-07-27 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.12 |
| Dependencies | 0 |
| Unpacked size | 18.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Sebastian Korfmann |
| Maintainers | skorfmann |
| Keywords | cdk, cdktf, constructs |

## Links

- npm: https://www.npmjs.com/package/cdktf-hybrid-module
- Repository: https://github.com/skorfmann/cdktf-hybrid-module
- Issues: https://github.com/skorfmann/cdktf-hybrid-module/issues
- npm.io page: https://npm.io/package/cdktf-hybrid-module

## Recent versions

- 0.0.1 (latest) — 2020-07-27

## README

# A Terraform CDK Construct which is usable as Terraform Module as well

This repo demonstratest the usage of a [cdktf](https://cdk.tf) 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.

## Getting started

```
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

## The general idea

- Synthesize a [stack without a provider](./packages/cdktf-hybrid-module/lib/module.ts) und use the synthesized folder as module.
- Release the [construct](./packages/cdktf-hybrid-module/lib/construct.ts) as part of the npm package
- As bonus, package the Terraform JSON as well, so you could use NPM as module manager

![cdktf-and-terraform](./cdktf-and-terraform.png)

See also this [blog post](https://dev.to/skorfmann/a-terraform-cdk-construct-which-doubles-as-native-terraform-module-447k).

## Examples

- [cdktf construct](./examples/cdktf-example)
- [Terraform module](./examples/terraform)
- [Terraform module npm](./examples/terraform-npm)

## Current Limitations

- Outputs are already fully supported by `cdktf` but due to the random naming a bit hard to use. There' an [open issue](https://github.com/hashicorp/terraform-cdk/issues/247) to address this
- Variables aren't directly supported in `cdktf`, but can still be done with [escape hatches](https://cdk.tf/escape-hatch). There's an [open issue](https://github.com/hashicorp/terraform-cdk/issues/249)
- 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](https://github.com/hashicorp/terraform-cdk/issues/98).

## Next Iteration

- [ ] Add [jsii](https://cdk.tf/jsii) for polyglot package
- [ ] Add unit tests
- [ ] Come up with a more realistic example for the construct

## Conclusion

While it's not the best user experience at this point, I think this demonstrates that the [Terraform CDK](https://cdkt.tf) 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

Contributions to this repository are more than welcome!

---
_Source: https://npm.io/package/cdktf-hybrid-module · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
