Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 8 additions & 4 deletions packages/@cdktn/hcl-tools/prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ if [[ -z "${GOROOT-}" ]]; then
exit 1
fi

if [ ! -f "$GOROOT/misc/wasm/wasm_exec.js" ]
then
echo "File $GOROOT/misc/wasm/wasm_exec.js does not exist!"
WASM_EXEC_PATH=""
if [ -f "$GOROOT/misc/wasm/wasm_exec.js" ]; then
WASM_EXEC_PATH="$GOROOT/misc/wasm/wasm_exec.js"
elif [ -f "$GOROOT/lib/wasm/wasm_exec.js" ]; then
WASM_EXEC_PATH="$GOROOT/lib/wasm/wasm_exec.js"
else
echo "File wasm_exec.js does not exist under either \$GOROOT/misc/wasm/ or \$GOROOT/lib/wasm/!"
exit 1
fi

cp "$GOROOT/misc/wasm/wasm_exec.js" ./wasm/wasm_exec.js
cp "$WASM_EXEC_PATH" ./wasm/wasm_exec.js

echo "Copied build system wasm_exec.js file to wasm/ directory."
12 changes: 8 additions & 4 deletions packages/@cdktn/hcl2json/prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ if [[ -z "${GOROOT-}" ]]; then
exit 1
fi

if [ ! -f "$GOROOT/misc/wasm/wasm_exec.js" ]
then
echo "File $GOROOT/misc/wasm/wasm_exec.js does not exist!"
WASM_EXEC_PATH=""
if [ -f "$GOROOT/misc/wasm/wasm_exec.js" ]; then
WASM_EXEC_PATH="$GOROOT/misc/wasm/wasm_exec.js"
elif [ -f "$GOROOT/lib/wasm/wasm_exec.js" ]; then
WASM_EXEC_PATH="$GOROOT/lib/wasm/wasm_exec.js"
else
echo "File wasm_exec.js does not exist under either \$GOROOT/misc/wasm/ or \$GOROOT/lib/wasm/!"
exit 1
fi

cp "$GOROOT/misc/wasm/wasm_exec.js" ./wasm/wasm_exec.js
cp "$WASM_EXEC_PATH" ./wasm/wasm_exec.js

echo "Copied build system wasm_exec.js file to wasm/ directory."
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,35 @@ exports[`readSchema generates a local module 1`] = `
}"
`;

exports[`readSchema generates a local module with inline comments in type constraints 1`] = `
"{
"format_version": "STUBBED VERSION",
"local_module": {
"inputs": [
{
"default": null,
"description": "A list of IAM policy statements",
"name": "iam_policy_statements",
"required": false,
"type": "any"
},
{
"description": "The name",
"name": "name",
"required": true,
"type": "string"
}
],
"name": "local_module",
"outputs": [
{
"name": "result"
}
]
}
}"
`;

exports[`readSchema generates a more complex schema 1`] = `
"{
"format_version": "STUBBED VERSION",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
Comment thread
so0k marked this conversation as resolved.
Resolved

variable "iam_policy_statements" {
description = "A list of IAM policy statements"
type = list(object({ # TODO - change to map(object({...})) in next major version
sid = optional(string)
actions = optional(list(string))
effect = optional(string)
resources = optional(list(string))
}))
default = null
}

variable "name" {
description = "The name"
type = string
}

output "result" {
value = "result"
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ describe("readSchema", () => {
expect(sanitizeJson(result)).toMatchSnapshot();
}, 120000);

it("generates a local module with inline comments in type constraints", async () => {
const module = new TerraformModuleConstraint({
name: "local_module",
fqn: "local_module",
source: path.resolve(
__dirname,
"fixtures",
"local-module-inline-comments",
),
});
const target = new ConstructsMakerModuleTarget(module, Language.TYPESCRIPT);
const result = await readModuleSchema(target);
expect(sanitizeJson(result)).toMatchSnapshot();
}, 120000);

it("generates a local json module", async () => {
const module = new TerraformModuleConstraint({
name: "local_module",
Expand Down
13 changes: 11 additions & 2 deletions packages/@cdktn/provider-schema/src/provider-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,17 @@ const transformVariables = (variables: any) => {
variableType = "any";
}
} else {
const matched = (variable["type"] as string)?.match(/\$\{(.*)\}/);
variableType = matched ? matched[1] : "any";
const rawVariableType = variable["type"];
if (
typeof rawVariableType === "string" &&
rawVariableType.startsWith("${") &&
rawVariableType.endsWith("}") &&
!rawVariableType.includes("\n")
) {
variableType = rawVariableType.slice(2, -1);
} else {
variableType = "any";
}
}

const item: Input = {
Expand Down
Loading