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

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

Open
gordonmurray opened this issue Jun 28, 2022 · 15 comments
Assignees
Labels
bug Something isn't working

Comments

@gordonmurray
Copy link

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.

@hugorut
Copy link
Collaborator

hugorut commented Jun 29, 2022

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

@hugorut hugorut added the bug Something isn't working label Jun 29, 2022
@hugorut hugorut self-assigned this Jun 29, 2022
@hugorut hugorut changed the title Extension seems to have trouble with a busy Workspace bug: Extension has issues when running in a multi-project VSCode workspace Jun 29, 2022
@hugorut hugorut changed the title bug: Extension has issues when running in a multi-project VSCode workspace bug: extension has issues when running in a multi-project VSCode workspace Jun 29, 2022
@hugorut hugorut changed the title bug: extension has issues when running in a multi-project VSCode workspace extension has issues when running in a multi-project VSCode workspace Jun 29, 2022
@hugorut hugorut changed the title extension has issues when running in a multi-project VSCode workspace Extension has issues when running in a multi-project VSCode workspace Jun 29, 2022
@gordonmurray
Copy link
Author

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.

@hugorut
Copy link
Collaborator

hugorut commented Jun 29, 2022

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
  }
}

@gordonmurray
Copy link
Author

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.

@hugorut
Copy link
Collaborator

hugorut commented Jun 29, 2022

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

@gordonmurray
Copy link
Author

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.

@hugorut
Copy link
Collaborator

hugorut commented Jun 29, 2022

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

@gordonmurray
Copy link
Author

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.

@hugorut
Copy link
Collaborator

hugorut commented Jun 29, 2022

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.

@gordonmurray
Copy link
Author

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

@hugorut
Copy link
Collaborator

hugorut commented Jun 30, 2022

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

@hugorut
Copy link
Collaborator

hugorut commented Jul 8, 2022

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.

@jghal
Copy link

jghal commented Mar 10, 2023

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

@hugorut
Copy link
Collaborator

hugorut commented Mar 13, 2023

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

@jghal
Copy link

jghal commented Mar 14, 2023

  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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants