winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.78k stars 189 forks source link

Generate Winglang bindings for arbitrary Terraform providers #4922

Open Chriscbr opened 7 months ago

Chriscbr commented 7 months ago

Feature Spec

As a user, I'd like a way to generate Wing bindings for any of the 3500+ Terraform providers so I can use any Terraform resource in my preflight code with type safety, autocompletion, and other goodness. This is similar to the facility provided by CDKTF (docs) for generating bindings in TypeScript, Python, and other languages.

For example, I might be able to run a command:

wing generate --tf pagerduty@~> 1.2

and then a .gen/pagerduty/ folder would be generated in my current project, with the bindings inside.

Then in my Wing application or library I can natively use the bindings like so:

bring "./gen/pagerduty" as pagerduty;

new pagerduty.schedule.Schedule();

Use Cases

Using Terraform providers that do not have publicly available bindings. The Terarform team only maintains bindings for a few dozen of the most popular Terraform providers like https://www.npmjs.com/package/@cdktf/provider-aws (these can be natively used in Wing since the npm packages include JSII metadata inside them).

Implementation Notes

It should be possible to generate the CDKTF bindings for TypeScript programmatically. Here's a script that generates TypeScript bindings for the kislerdm/neon provider inside a .gen directory.

import { ConstructsMaker } from "@cdktf/provider-generator";
import { Language } from "@cdktf/commons";

async function main() {
  const constructsMaker = new ConstructsMaker({
    targetLanguage: Language.TYPESCRIPT,
    codeMakerOutput: ".gen/",
  });
  await constructsMaker.generate([{
    name: "neon",
    fqn: "neon",
    version: '~> 0.2',
    source: 'kislerdm/neon',
    namespace: 'kislerdm',
  }]);
}

main().catch(err => {
  console.error(err);
  process.exit(1);
});

These TypeScript bindings would have to be part of a JSII library before they can be recognized and imported in Wing.

Component

SDK, CLI

Community Notes

github-actions[bot] commented 5 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

Chriscbr commented 4 months ago

This would let us create bindings for CIVO resources and use them in Wing: https://registry.terraform.io/providers/civo/civo/latest/docs

eladb commented 1 month ago

See tf.Resource for an untyped experience: https://github.com/winglang/winglibs/blob/main/tf/README.md

Should be pretty reasonable for most use cases.