terraform-cdk: 0.3.0 breaking local module in subdirectory

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

cdktf & Language Versions

cdktf version: 0.3.0 typescript: 4.2.4

Affected Resource(s)

TerraformHclModule

Debug Output

Expected Behavior

new TerraformHclModule(this, stackName, {
    source: "./terraform",
    variables: {
        ...
    },
});

Should result in module path being ./terraform

Actual Behavior

Module path is ../terraform

Running subsequent cdktf deploy fails since it canโ€™t find the module.

Steps to Reproduce

Create a subfolder with a terraform HCL module in it, then call cdktf deploy

Important Factoids

References

In cdktf.out/stacks/<stack_name>/cdk.tf.json, the rendered source is โ€œโ€ฆ/terraformโ€

Looks like it may have been introduced here: https://github.com/hashicorp/terraform-cdk/blob/e39f5e5847b9eb928f17be51d5f8f42ea5ab3112/packages/cdktf/lib/terraform-module.ts#L31

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Just tested with cdktf 0.6.4 and looks like this has been solved

This can be solved now by either using

a) the local module binding generation: https://github.com/hashicorp/terraform-cdk/blob/main/docs/working-with-cdk-for-terraform/using-modules.md#generated-terraform-module-bindings

b) using the Asset construct to move the HCL Module:

const tfModule = new Asset(this, "myModule", {
  path: "./terraform"
})

new TerraformHclModule(this, stackName, {
    source: tfModule.path,
    variables: {
        ...
    },
});

Let me know if this helps ๐Ÿ˜ƒ

I encounter the same issue with cdktf 0.5.0 and Python 3.7.5

Thanks for the additional information. Iโ€™ll double check where terraform is running from when using cdktf to make sure it aligns with that recent change for local module generation and the new multiple stacks changes.