Skip to content

Commit

Permalink
fix(hcl2cdk): handle all global variables
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Jul 26, 2021
1 parent 00f8e47 commit 99f3302
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/@cdktf/hcl2cdk/lib/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export function extractReferencesFromExpression(
spot.endsWith("...") || // spread (likely in for loop)
spot.startsWith("count.") || // count variable
spot.startsWith("each.") || // each variable
spot.startsWith("path.module") // path variable
// https://www.terraform.io/docs/language/expressions/references.html#filesystem-and-workspace-info
spot.startsWith("path.module") ||
spot.startsWith("path.root") ||
spot.startsWith("path.cwd") ||
spot.startsWith("terraform.workspace")
) {
return carry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,14 @@ new auth0.Auth0Provider(this, \\"auth0\\", {
"
`;
exports[`convert required namespaced provider configuration 2`] = `
"new TerraformHclModule.TerraformHclModule(this, \\"example\\", {
namePrefix: \\"app-\${terraform.workspace}\\",
source: \\"./my-module\\",
});
"
`;
exports[`convert resource references configuration 1`] = `
"import * as aws from \\"./.gen/providers/aws\\";
const awsKmsKeyExamplekms = new aws.KmsKey(this, \\"examplekms\\", {
Expand Down
9 changes: 9 additions & 0 deletions packages/@cdktf/hcl2cdk/test/hcl2cdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,15 @@ describe("convert", () => {
}
`,
],
[
"required namespaced provider",
`
module "example" {
source = "./my-module"
name_prefix = "app-\${terraform.workspace}"
}
`,
],
])("%s configuration", async (_name, hcl) => {
const { all } = await convert(hcl, {
language: "typescript",
Expand Down

0 comments on commit 99f3302

Please sign in to comment.