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

feat(hcl2cdk): Support Go in convert command #1782

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/@cdktf/hcl2cdk/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as glob from "glob";
import * as fs from "fs";
import { DirectedGraph } from "graphology";
import * as rosetta from "jsii-rosetta";
import { GoVisitor } from "jsii-rosetta/lib/languages/go";
import * as z from "zod";

import { schema } from "./schema";
Expand Down Expand Up @@ -404,6 +405,8 @@ const translations = {
rosetta.translateTypeScript(file, new rosetta.JavaVisitor()).translation,
csharp: (file: File) =>
rosetta.translateTypeScript(file, new rosetta.CSharpVisitor()).translation,
go: (file: File) =>
rosetta.translateTypeScript(file, new GoVisitor()).translation,
};

type ConvertOptions = {
Expand Down
24 changes: 24 additions & 0 deletions packages/@cdktf/hcl2cdk/test/__snapshots__/hcl2cdk.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ new S3BucketObject.S3BucketObject(this, \\"examplebucket_object\\", new Struct {
});"
`;

exports[`convert Cross-Language Support supports go 1`] = `
"/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import \\"github.com/aws-samples/dummy/gen/providers/aws/kmsKey\\"
import \\"github.com/aws-samples/dummy/gen/providers/aws/s3Bucket\\"
import \\"github.com/aws-samples/dummy/gen/providers/aws/s3BucketObject\\"
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: aws.
For a more precise conversion please use the --provider flag in convert.*/
awsKmsKeyExamplekms := kmsKey.NewKmsKey(this, jsii.String(\\"examplekms\\"), map[string]interface{}{
\\"deletion_window_in_days\\": jsii.Number(7),
\\"description\\": jsii.String(\\"KMS key 1\\"),
})
awsS3BucketExamplebucket := s3Bucket.NewS3Bucket(this, jsii.String(\\"examplebucket\\"), map[string]*string{
\\"acl\\": jsii.String(\\"private\\"),
\\"bucket\\": jsii.String(\\"examplebuckettftest\\"),
})
s3BucketObject.NewS3BucketObject(this, jsii.String(\\"examplebucket_object\\"), map[string]interface{}{
\\"bucket\\": fmt.Sprintf(\\"\\\\\\\\\${element(%v, 0).id}\\", awsS3BucketExamplebucket.fqn),
\\"key\\": jsii.String(\\"someobject\\"),
\\"kms_key_id\\": awsKmsKeyExamplekms.arn,
\\"source\\": jsii.String(\\"index.html\\"),
})"
`;

exports[`convert Cross-Language Support supports java 1`] = `
"/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
Expand Down
2 changes: 1 addition & 1 deletion packages/@cdktf/hcl2cdk/test/hcl2cdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { convert } from "../lib/index";

describe("convert", () => {
const targetLanguages = ["typescript", "python", "csharp", "java"];
const targetLanguages = ["typescript", "python", "csharp", "java", "go"];
describe("Cross-Language Support", () => {
it.each(targetLanguages)("supports %s", async (language) => {
const hcl = `
Expand Down
2 changes: 1 addition & 1 deletion packages/cdktf-cli/src/bin/cmds/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Command extends BaseCommand {
"Takes the HCL content of main.tf and converts it to CDK for Terraform content in imported.ts"
)
.option("language", {
choices: ["typescript", "python", "csharp", "java"],
choices: ["typescript", "python", "csharp", "java", "go"],
default: readCdktfJson()?.language || "typescript",
})
.option("provider", {
Expand Down