Open
Description
Description
The example provided in the npm docs is broken: https://www.npmjs.com/package/@cdktf/hcl2cdk.
I got the simple inline example working like so. I'm unsure if this can be further simplified.
import * as hcl2cdk from "@cdktf/hcl2cdk";
import {readSchema} from "@cdktf/provider-schema";
import { ConstructsMakerProviderTarget, LANGUAGES, TerraformProviderConstraint } from "@cdktf/commons";
const hcl = `
variable "name" {
description = "Name to be used on all the resources as identifier"
type = string
default = ""
}
`;
(async () => {
const providerRequirements = await hcl2cdk.parseProviderRequirements(hcl);
const targets = Object.entries(providerRequirements).map(([name, version]) =>
ConstructsMakerProviderTarget.from(
new TerraformProviderConstraint(`${name}@ ${version}`),
LANGUAGES[0]
)
);
const { providerSchema } = await readSchema(targets);
const ts = await hcl2cdk.convert(hcl, {
language: "typescript",
providerSchema: providerSchema
});
console.log(ts.imports); // just the necessary imports
console.log(ts.code); // just the constructs
console.log(ts.all); // code with imports
})();
It'd be excellent to update the docs indicating the split/rename of some of these fields and exports. I'm unsure how the project conversion works at this time, would appreciate some guidance here.
Links
https://www.npmjs.com/package/@cdktf/hcl2cdk
Help Wanted
- I'm interested in contributing a fix myself
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