Skip to content

App({ hclOutput: true }) is ignored: the stack writes JSON into cdk.tf #561

Closed

Description

@jsteinich

Expected Behavior

new App({ hclOutput: true }) synthesizes HCL into stacks/<name>/cdk.tf.

Actual Behavior

The manifest names the file cdk.tf, but the stack writes JSON into it, so the file can't be parsed. Only SYNTH_HCL_OUTPUT=true produces real HCL.

const app = new App({ outdir: "out", hclOutput: true });
const stack = new TerraformStack(app, "s");
new TerraformVariable(stack, "v", { type: VariableType.STRING });
app.synth();
// out/stacks/s/cdk.tf contains `{ "//": ..., "variable": { ... } }`

Reproduced on upstream/main by running the library directly, the same way unit tests and Testing.app() users would.

Cause

Two settings that should agree don't:

  • App resolves hclOutput from the config, with SYNTH_HCL_OUTPUT taking precedence (app.ts:102-108). The manifest uses that value for the file extension.
  • TerraformStack builds its StackSynthesizer from the env var alone (terraform-stack.ts:124-129), and that decides the file's contents.

Under the CLI, synth-stack.ts always sets SYNTH_HCL_OUTPUT from --hcl (synth-stack.ts:145). The two values match there, but the hclOutput config is always overridden, so it does nothing.

Possible Solutions

Have StackSynthesizer read the resolved App.of(stack).hclOutput at synth time instead of reading the env var in the stack constructor. Then the config, the env var and the manifest all go through the same precedence in App.

Upstream cdktf Issue

hashicorp/terraform-cdk#3875 (open)

References

Blocks HCL-mode unit tests that use Testing.app({ hclOutput: true }). See #563.

Activity

  1. added a commit that references this issue on Nov 11, 2026
    ca9b635
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeature/hcl-synthHCL output of synth (synth --hcl)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions