cdktf / cdktf-provider-project

Repository management for prebuilt cdktf providers via cdktf
https://cdk.tf
Mozilla Public License 2.0
18 stars 15 forks source link

Support for Terraform modules #325

Open rlmartin opened 1 year ago

rlmartin commented 1 year ago

Description

I am working on a CDKTF Construct that uses a Terraform module for some of its resources. I was going to take the same approach with the module "dependency" as the recommended approach for providers - which seems to be to reference pre-built providers as peer dependencies of the construct. Does this seem like a reasonable approach?

If this is the right approach, I was looking for the established pattern to produce pre-built modules based on existing Terraform modules. I found the project-cdktf-hybrid-construct, which seems like a first attempt, but it appears only lightly maintained - plus does not include the nice auto-upgrade feature provided by this template for providers.

As such, I was considering considering tweaking this project template to also support Terraform modules. I don't have a strong opinion on whether it is a fork of this repo vs an alternative configuration option - would take any input. The necessary change seems somewhat minor - I think I could even take it on myself and submit a PR. But before doing that work I wanted to see if people feel like this is the right direction.

I think the thing that I don't intuitively understand is where Terraform dependencies will result in conflicts - and how to avoid/manage that. For example, the pre-built library that is generated for the Terraform module will most likely depend on one or more Terraform providers. If the repo using the pre-built module library uses the same provider in a pre-built manner but that provider is built from a different Terraform provider version than the one in the pre-built module - will this be a problem?

References

No response

Help Wanted

Community Note

ansgarm commented 1 year ago

Hi @rlmartin 👋

While we currently don't have concrete plans for publishing pre-built modules ourselves, we'd probably start with duplicating this Projen template into a new repository and adjusting it to the needs for Terraform modules (which probably would mean simplifying some things and adjusting others, like e.g. the upgrade flow). Even if we currently don't have plans for pre-built modules, we'd still welcome you taking a stab at this and would be open to give feedback and be there for any questions that might pop up. But we also can't promise that we'd continue the work you start.

The dependency problem you mention is a hard one that still needs a solution 😅 However, modules don't require the provider to be present when their bindings are generated and compiled, so we could even shift that responsibility to the user. Specifying a peerDependency would probably be the best UX, but a user could still use locally generated bindings with an incompatible version 😄 So yeah, this needs some deeper thoughts.