Open skorfmann opened 3 years ago
While I think part of the hard part would be creating a maintained plugin framework to simplify custom resources (see below), I was also thinking about how CDKTF might bootstrap these custom "plugins".
In very abbreviated psudeo form, my thought process was:
cdktf
or another cli, provides a generic entrypoint like cdktf plugin-exec
which handles the Go Plugin Handshake as well as standing up a compatible gRPC
server and loading the plugin implementation.provider_installation {
filesystem_mirror {
path = "<output-dir>/plugin/bin/entrypoint"
include = ["terraform-cdk.local/*/*"]
}
direct {
exclude = ["terraform-cdk.local/*/*"]
}
}
import { App, Stack } from "cdktf";
import { CustomProvider, CustomResource, Handler } from "cdktf/custom_resource";
/ ... some code ... / const provider = new CustomProvider(this, "MyProvider", { // Gets translated into the entrypoint defined above as appropraite handler: Handler.fromNodejs(path.join(__dirname, "src/index.js")), }); new CustomResource(this, "MyResource", { provider, // CDKTF can probably handle auto-prefixing resoruces" resource: "my_resource", properties: / my properties /, }); / ... more code ... /
The hard part off course is after. Creating NodeJS plugins is one thing, creating plugins that will work in any of CDKTF's supported runtimes is another matter. CloudFormation and the AWS CDK supports this via Lambda's runtime support and well-defined event model but it's not so simple with local execution.
A possibility is a JSII provided meta-framework that effectively duplicates https://github.com/hashicorp/terraform-plugin-framework via JSII, but you still have to solve for the communication layer between Terraform and the plugin without leaking too much to the consumer. I'm not sure there's a reasonable low effort way to support this in other language and an MVP might just be to implement Node-based custom resources and punt on JSII-based ones.
Community Note
Description
It'd be fantastic to have the option to create custom, stateful resources on the fly. Essentially an
cdktf-adhoc-provider
, which acts as a Terraform Plugin. This should be auto generated from user written code.Prior Art
There is the https://github.com/lukekaalim/terraform-plugin-node-SDK project which is doing something like this for nodejs already. While it seems to be more like a proof of concept, their readme describes the use-cases I have in mind pretty well:
There's also an example how their implementation looks like.