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

cdktf unable to parse modules without newlines at EOF #595

Closed
celliott opened this issue Mar 12, 2021 · 6 comments · Fixed by #633
Closed

cdktf unable to parse modules without newlines at EOF #595

celliott opened this issue Mar 12, 2021 · 6 comments · Fixed by #633
Labels
bug Something isn't working cdktf-cli modules
Milestone

Comments

@celliott
Copy link

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

using typescript@4.2.3 and cdktf 0.2.0

Affected Resource(s)

cdktf importing of custom modules

Debug Output

i'm using the new module improvements from #584 to source modules locally and from github. It is works as expected unless a module's variables and/or outputs tf files do not have a newline at EOF. cdktf fails to parse those modules. Add a newline to EOF for suspect files and then cdktf will successful parse and import the module.

error gist

example terraformModules

"terraformModules": [
  {
    "name": "s3",
    "source": "git@github.com:mycompany/terraform-aws-s3.git"
  }
],

Expected Behavior

I would expect to be able to import a module that works without error when using tarraform directly. It's easy to fix but it wasn't clear at first what the issue was. If there is no fix, then better documentation and error messaging would help.

Actual Behavior

A source a custom tf module with the improved module importing and any module that doesn;t have new lines at EOF fail to parse. I have tested with both local or github sourced modules and as expected, the behavior is the same.

Steps to Reproduce

Source a module from local or github using terraformModules in cdktf.sjon. Make sure that the file containing either outputs or variables does NOT have a newline at EOF. Run cdktf get and the module with fail to import. Add a newline to the end of the file(s), reimport and it will work as expected.

@celliott celliott added the bug Something isn't working label Mar 12, 2021
@danieldreier danieldreier added this to the 0.3 milestone Mar 16, 2021
@jsteinich
Copy link
Collaborator

I'm having some trouble reproducing this issue. @celliott are you able to provide a simple module which reproduces this? Also what version of terraform are you using?

@jsteinich
Copy link
Collaborator

I have a thought as to what is causing this. Likely same issue as xchapter7x/clarity#23 (reference) since file contents are also concatenated here.

@celliott
Copy link
Author

celliott commented Apr 15, 2021

@jsteinich I am using Terraform v0.14.6. I don't have an example that I can share but I can create one if you need. I can show you the fix that resolved my issue. No newline after a variable or output causes the issue. I haven't rechecked with cdktf 0.2.1.

vars

@celliott
Copy link
Author

@jsteinich I updated repo with an example and added a cdktf.json. I am using cdktf 0.2.1. I hope this helps.

$ git clone git@github.com:celliott/tf-example.git
$ cd tf-example
$ cdktf get
Error: parse config: [hcl2json.tf:93,2-11: Missing newline after block definition; A block definition must end with a newline.]
    at cb (/usr/local/lib/node_modules/cdktf-cli/node_modules/@cdktf/hcl2json/lib/index.js:48:63)
    at syscall/js.valueInvoke (/usr/local/lib/node_modules/cdktf-cli/node_modules/@cdktf/hcl2json/lib/wasm_exec.js:190:48)
    at wasm-function[1489]:0x1517da
    at wasm-function[1472]:0x14fa33
    at wasm-function[3109]:0x3f0f9a
    at wasm-function[977]:0xd73a3
    at wasm-function[976]:0xd7384
    at Go._resume (/usr/local/lib/node_modules/cdktf-cli/node_modules/@cdktf/hcl2json/lib/wasm_exec.js:276:36)
    at /usr/local/lib/node_modules/cdktf-cli/node_modules/@cdktf/hcl2json/lib/wasm_exec.js:447:18
    at run (/usr/local/lib/node_modules/cdktf-cli/node_modules/@cdktf/hcl2json/lib/index.js:50:37)
⠙ downloading and generating modules and providers...
parse config: [hcl2json.tf:93,2-11: Missing newline after block definition; A block definition must end with a newline.]

@jsteinich
Copy link
Collaborator

Thanks for the update. I believe that I've found the root cause and have a PR open to address.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2022

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working cdktf-cli modules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants