infracost / vscode-infracost

See cost estimates for Terraform right in your editor💰📉

Home Page:https://www.infracost.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extension has issues when running in a multi-project VSCode workspace

gordonmurray opened this issue · comments

I installed the extension this evening, on VS Code 1.68.1.

At first I didn't think it was working. I have a Workspace in VS Code with over a dozen Terraform projects.

I closed the workspace and opened just 1 Terraform project and it worked perfectly.

I added a second folder to the Workspace and it didn't work for the second project, but the first one was still ok, prices changed when appropriate.

My profile has a number of open Terraform projects if that helps debugging.

Hello @gordonmurray, thanks for raising the first issue on vscode-infracost 🎉 ! Sorry to hear that Infracost is being finicky about your multi-workspace environment. I've got some further questions which will help me debug what's going on behind the scenes:

  1. Could you run infracost breakdown --path . in the top-level folder of the original workspace (the one with over a dozen Terraform projects) and see if you get a successful output.
  2. If you got a successful output to question 1. could you open the VSCode workspace again. It might be that Infracost is slow to index all the projects. There's a status icon in the bottom right corner of the editor, which should show
    loading
    SCR-20220629-bkw
    or success
    SCR-20220629-bkm
  3. If step 1. failed can you post the error here
  4. Adding the second folder to the Workspace - I think this is a bug that we can't detect new projects, because we're caching the files that point to specific Terraform projects so that we don't have to run all the projects again. Could you close and reopen that Workspace and see if the second project now shows prices. We fetch all the projects when first opening the Workspace so this should provide a workaround for this until we get a fix in.

Many thanks

Hi Hugo,

Thanks for responding. Tried those steps just now:

  1. I ran an Infracost breakdown in the top level folder, all good, no issues there.
  2. The Infracost little cloud icon in the status bar seems static, doesn't look like it was processing at any time.
  3. No visible errors
  4. I closed and reopened the 2 project workspace. Still the same. No change in the Infracost image in the status bar and no costs appearing in the second project even if changes are made and saved.

hmm, @gordonmurray could you try posting the following block into a random file in both workspaces (the large and the 2 project one) saving and seeing if you have any prices displayed?

resource "aws_instance" "web_app" {
  ami           = "ami-674cbc1e"
  instance_type = "m5.4xlarge" 

  root_block_device {
    volume_size = 50
  }

  ebs_block_device {
    device_name = "my_data"
    volume_type = "io1" 
    volume_size = 1000
    iops        = 800
  }
}

Are you trying to sneak an ec2 instance in to my account? :)

I added the snippet to the small 2-project workspace, It gave me a cost of $825.98 in the first project but didn't show for the second project.

I added the snippet to one or two projects in the busy workspace also, no output.

I didn't see the Infracost status process at any time in case that should animate or anything.

Haha, bitcoin mining you know... although that might not fetch much these days. Hmm weird, could you:

  1. navigate to the 2-project workspace
  2. open the file that holds the ec2 instance
  3. open the extension terminal (Terminal->New Terminal)
  4. select "Output" and "log (Window)
    SCR-20220629-frs
  5. alter instance_type to "m5.8xlarge" and save the file
  6. see if there's any output in the logs there - copy and paste it here

When I open the tf file, even before making a change I get the following output

Screenshot from 2022-06-29 12-13-53

I tried looking at the file mentioned (/home/gordon/.vscode/extensions/hashicorp.terraform-2.23.0-linux-x64/out/extension.js) though its minified and doesn't make much sense even if I try to format it.

I could try removing extensions and try it with just Terraform and Infracost.

hmm @gordonmurray I'd just ignore that and see if there's any Infracost output if you scroll. I have a ton of random error logs as well

I removed all but 2 extensions from VS Code ( Terraform and Infracost) in case some other extension was causing an issue, no luck I'm afraid.

While working away for a while, the only output to appear is this:

Screenshot from 2022-06-29 19-59-03

Overall if this is only happening to me, I'm happy to close this issue if you prefer.

hmm no @gordonmurray I'd love to get to the bottom of this. Would you be open to scheduling a call with me so we can debug together? It would be easier and hopefully, save your time going back and forth.

Sure, Im in a GMT timezone. Suggest a day and time and Ill try to make it.

cool @gordonmurray I'm GMT too, could you ping me an email to hugo@infracost.io and I'll reply back with some time. Thanks

Updates from today's debugging session with @gordonmurray, there are a few bugs here, some of which need further investigation to find out what is going on:

  1. If a user creates a new project in an already active VSCode workspace, Infracost extension will not pick this up until the workspace has been closed and reopened. This is a known issue and we are actively working on supporting this.
  2. If a user creates a greenfield Terraform project in VSCode Infracost extension will not pick this up until the workspace has been closed and reopened. This is because the VSCode extension activation events aren't fired.
  3. We experienced a strange bug when using a multi-project workspace with private modules. The infracost CLI was showing the correct output but these were not being applied as codelenses. When opened as a single project the lenses showed correctly. The project was made up of mostly module calls to a private modules hosted git. I'm wondering if there's some collision going on with filenames.

Any update on this? I just discovered Infracost and am seeing the same issue still.

Name: Infracost
Id: Infracost.infracost
Description: Cloud cost estimates for Terraform in your editor
Version: 0.2.6
Publisher: Infracost
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=Infracost.infracost
Version: 1.76.1 (user setup)
Commit: 5e805b79fcb6ba4c2d23712967df89a089da575b
Date: 2023-03-08T16:32:00.131Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: Yes

Hey @jghal, so just to confirm your issues here's a few follow up questions:

  1. Is the Infracost project sidebar correctly displayed (is it showing you price estimates for your multiple projects)
  2. Are you seeing any code lens prices in any project? Or are they not displayed in any project
  3. If you open a single project in vscode - do you correctly see estimates?
  4. Are there any Infracost debug logs (see README) that look suspicious?

Thanks

  1. Selecting the Infracost view from the sidebar wasn't showing any contents with multiple projects open in my workspace (some with Terraform code, some not).
  2. No code lens prices displayed with multiple projects open
  3. Removing all but one Terraform project I start to see the code lens pricing info in the source file(s), and the infracost overview view displays data.
  4. I see messages like this
debug: setting context infracost:active to true
debug: setting context infracost:loggedIn to true
debug: initializing workspace
debug: running Infracost in project: /home/justin/Code/gitlab.com/ado-agent
debug: running Infracost breakdown
debug: setting context infracost:error to undefined
debug: providing codelens for file /home/justin/Code/gitlab.com/terraform-azure-provisioner/main.tf
debug: initializing workspace
debug: running Infracost in project: /home/justin/Code/gitlab.com/ado-agent
debug: running Infracost breakdown
debug: setting context infracost:error to undefined
debug: providing codelens for file /home/justin/Code/gitlab.com/terraform-azure-provisioner/main.tf
debug: providing codelens for file /home/justin/Code/gitlab.com/terraform-azure-provisioner/main.tf

I did try running infracost breakdown --path like you suggested earlier in the thread, and that seems to work fine, but I did notice something interesting there. The projects I have in this workspace are the Git repos for the modules we write, rather than the Terraform workspace repos that would include calls to the modules. My goal is to have the module developers seeing the cost impact of the modules in their IDEs, and then also to use the CI integration to see the cost delta in their PRs. The infracost breakdown command showed data from the tests folder where we have extra TF code to test the module (we use terratest), and not from the module's code itself. The IDE plugin is showing data from the module code, not the tests directory code. I haven't tried looking at a an actual Terraform workspace config project, where we call these modules. I will note that our modules are in private git repos, but we currently use the git repo url as the module source, and would have a Gti credential manager going so that a terraform init doesn't prompt for pulling every module.

When I added a second Terraform module project to the workspace (so multiple projects, but all of them Terraform module sources), the Infracost overview view showed the added project's price data and not the one that was already present. This could have been just me not waiting long enough though, the extension status icon was showing the animated arrows circle.