Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Resources #661

Open
skorfmann opened this issue Apr 22, 2021 · 1 comment
Open

Custom Resources #661

skorfmann opened this issue Apr 22, 2021 · 1 comment
Labels
cdktf enhancement New feature or request feature/dynamic-terraform priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. size/large estimated < 1 month

Comments

@skorfmann
Copy link
Contributor

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

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:

Why create Plugins?
Terraform has a wealth of plugins available to it already created that allow you to manage a vast amount of resources in an interconnected graph, but it doesn't have all of them.

When using terraform, you may wish to:

  • Create resources that talk to a proprietary or internal API
  • Create resource for an API that doesn't have a provider yet
  • Manage a resource for an existing provider that doesn't provide certain functionality
  • Disagree with the implementation of an API and want to give yourself greater flexibility
  • Model existing build scripts as declarative structures

There's also an example how their implementation looks like.

@skorfmann skorfmann added enhancement New feature or request cdktf labels Apr 22, 2021
@DanielMSchmidt DanielMSchmidt added needs-priority Issue has not yet been prioritized; this will prompt team review size/large estimated < 1 month labels Dec 6, 2021
@DanielMSchmidt DanielMSchmidt added priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. and removed needs-priority Issue has not yet been prioritized; this will prompt team review labels Feb 10, 2022
@RichiCoder1
Copy link

RichiCoder1 commented Feb 26, 2023

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, either via 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.
  • CDKTF emits a special configuration like:
provider_installation {
  filesystem_mirror {
    path    = "<output-dir>/plugin/bin/entrypoint"
    include = ["terraform-cdk.local/*/*"]
  }
  direct {
    exclude = ["terraform-cdk.local/*/*"]
  }
}
  • CDKTF then dynamically loads/runs the plugin implementation as defined in code like:
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cdktf enhancement New feature or request feature/dynamic-terraform priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. size/large estimated < 1 month
Projects
None yet
Development

No branches or pull requests

4 participants