vscode-infracost icon indicating copy to clipboard operation
vscode-infracost copied to clipboard

Extension fails to run in large workspaces that aren't fully Terraform

Open ddulic opened this issue 2 years ago • 3 comments

Hello, I am seeing the following issue

Could not run the infracost cmd in the /Users/ddulic/Work/work-project-name directory. This is likely because of a syntax error or invalid project. See the Infracost Debug output tab for more information. Go to View > Output & select "Infracost Debug" from the dropdown. If this problem continues please open an issue here: https://github.com/infracost/vscode-infracost.
debug: initializing workspace
debug: running Infracost in project: /Users/ddulic/Work/work-project-name
debug: running Infracost cmd INFRACOST_CLI_PLATFORM=vscode infracost breakdown --path "/Users/ddulic/Work/work-project-name" --format json --log-level info
error: Infracost cmd error trace Error: Command failed: INFRACOST_CLI_PLATFORM=vscode infracost breakdown --path "/Users/ddulic/Work/work-project-name" --format json --log-level info
[91mError:[0m No valid Terraform files found at the given path, try a different directory

Try setting --path to a Terraform plan JSON file. See [4;1mhttps://infracost.io/troubleshoot[0m for how to generate this.

I am assuming that the issue is that I have a large workspace where not all projects are Terraform projects.

This should not prevent the extension from running.

Reinstalling the expansion doesn’t resolve the issue.

I am able to run infracost breakdown --path . directly in the Terraform projects to get the output, but the extension still doesn’t work.

Running infracost breakdown --path . in the top-level folder housing all the projects works as intended and skips the folders that aren’t TF.

ddulic avatar Jul 21 '22 10:07 ddulic

hey @ddulic, thanks for raising this issue.

So the extension should be fine running in a workspace where not all projects are Terraform projects. At this point the extension is just a UI wrapper for the binary, so it's a bit weird that you can run infracost breakdown --path . in the /Users/ddulic/Work/work-project-name from your terminal and it be fine. I've got a few follow up questions to hopefully debug what's going on here:

  1. could you run infracost breakdown --path /Users/ddulic/Work/work-project-name --format json --log-level info where the /Users/ddulic/Work/work-project-name is the real file path show in the Infracost debug log. Does this succeed?
  2. If you answer no to the above could you run infracost breakdown --path /Users/ddulic/Work/work-project-name --format json --debug-report and upload the infracost-debug-report.json created here.
  3. If yes to point 1 could you try and open one of the valid terraform projects under /Users/ddulic/Work/work-project-name as a VSCode workspace and see if Infracost can work within it?
  4. Could you write a shallow tree output of the /Users/ddulic/Work/work-project-name and post it here? Highlighting which folders are root Terraform projects e.g.:
/Users/ddulic/Work/work-project-name/
    folder/
    myfolder/
    myproject/ # tf project
    infra/
         dev/ #tf project
         prod/ #tf project

Thanks

hugorut avatar Jul 21 '22 11:07 hugorut

Thanks for the prompt reply @hugorut!

it's a bit weird that you can run infracost breakdown --path . in the /Users/ddulic/Work/work-project-name from your terminal and it be fine.

Actually, that was just me confirming that I can run infracost directly in Terraform projects, and it works, just to clarify that the CLI tool is working.

When I attempt to run it in the folder that is causing the extension to crash I get the following:

~/Work/work-project-name
❯ infracost breakdown --path .
Error: No valid Terraform files found at the given path, try a different directory

Try setting --path to a Terraform plan JSON file. See https://infracost.io/troubleshoot for how to generate this.

Just wanted to clarify that.


So /Users/ddulic/Work/work-project-name is not a TF Project. Would you still like me to run all the debug steps?

ddulic avatar Jul 21 '22 13:07 ddulic

@ddulic does /Users/ddulic/Work/work-project-name have any terraform projects in? If so how many nested folders deep are these? I think the maximum level of folder nesting we check is 5 layers deep.

If these are less than 5 folders deep, yes please I'd love if you could run the debug steps. Thanks

hugorut avatar Jul 21 '22 13:07 hugorut