infracost / vscode-infracost Goto Github PK
View Code? Open in Web Editor NEWSee cost estimates for Terraform right in your editor💰📉
Home Page: https://www.infracost.io/
License: Apache License 2.0
See cost estimates for Terraform right in your editor💰📉
Home Page: https://www.infracost.io/
License: Apache License 2.0
Infracost VSCode extension relies on the Infracost CLI to parse and fetch cost estimates. However, the CLI is yet to support private Terraform modules. See this issue infracost/infracost#1667 for more information. This means that the extension will fail with a "something wen't wrong" message. Until infracost/infracost#1781 is meged and v0.10.7 of the CLI is released users should do the following if they have private modules in their workspaces:
cd
into the project folderrm -rf .infracost
terraform init
Then reopen the workspace in your editor and the Infracost extension should work as expected
Hi!
Can you please publish this extension to the Open VSX marketplace?
Unfortunately, as Microsoft prohibits usages of the Microsoft marketplace by any other products or redistribution of .vsix files from it, in order to use VS Code extensions in non-Microsoft products, I kindly ask that you take ownership of the VS Code extension namespace in Open VSX and publish this extension on Open VSX.
Open VSX is a vendor neutral alternative to the MS marketplace used by most other derivatives of VS Code like VSCodium, Gitpod, OpenVSCode, Theia-based IDEs, and so on.
The docs to publish an extension can be found here. This process is straightforward and shouldn't take too long. Essentially, you need an authentication token and to execute the command ovsx publish to publish your extension. At Open VSX we also wrote a short doc explaining an easy way to use GitHub Actions to automate the whole publishing process.
After installing the extension, when I open a non-Terraform project I see an error message.
Expected result:
I don't see anything since I'm not expecting Infracost to try to run on my non-Terraform projects.
Actual result:
The following error pops up:
Could not run the infracost cmd in the XXX directory. If this is a multi-project workspace please try opening just a single project. If this problem continues please open an issue here: https://github.com/infracost/vscode-infracost.
"If this is a multi-project workspace please try opening just a single project. If this problem continues please open an issue here:"
I continue to receive this message within ll of my different TF directories no matter the structure.
I have installed infracost, registered or an API key, and enabled the extension within VS Code.
Infracost VSCode extension only shows a breakdown snapshot of current cloud estimates. It would be great to show users a diff
of their current changes vs the main
or user-defined branch.
Note for community
Please 👍 if you'd like to upvote this or receive updates.
Add a comment if you'd like to contribute.
If users start a new Terraform project in VSCode the Infracost extension fails to activate because there are no .tf
files in the project.
A workaround for this is to close and reopen the workspace (or disable and reenable the extension) when some .tf
files have been added.
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.
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.
The Infracost VSCode extension has multi-project support through native auto-detection. However, many users might have variables and settings supplied through an Infracost config file. We should allow users to supply config files through an extension setting or through parsing a common name/location.
Note for community
Please 👍 if you'd like to upvote this or receive updates.
Add a comment if you'd like to contribute.
Infracost requires the Hashicorp Terraform Extension installed to provide code lens support.
Since v2.24.0 of Terraform extension code lenses seem to be broken. Calls to get code symbols for Terraform files to return an empty list. This means that cost estimates do not show above supported Terraform blocks.
The team will look at this ASAP and get a fix out. In the interim, we recommend you downgrade your Terraform extension version to v2.23.0
.
When loading a large workspace (260+ .tf
files) in order to estimate a subset of it, breakdown
fails with stdout maxBuffer length exceeded
. Ideally, I could breakdown just the main.tf
in the workspace I'm interested in evaluating and lazily load dependent modules, but it seems infracost is trying to load everything proactively.
debug: initializing workspace
debug: running Infracost in project: c:\Code\terraform-configuration
debug: running Infracost cmd cmd /C "set INFRACOST_CLI_PLATFORM=vscode && infracost breakdown --path "c:\Code\terraform-configuration" --format json --log-level info"
error: Infracost cmd error trace RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]: stdout maxBuffer length exceeded
debug: providing codelens for file /c:/Code/terraform-configuration/.../main.tf
Wrong path when runnin on windows.
debug: initializing workspace
debug: running Infracost in project: c:\Users\Mirusky\Desktop\ultimate-project
debug: running Infracost cmd cmd /C "set INFRACOST_CLI_PLATFORM=vscode && infracost breakdown --path [object Object] --format json --log-level info"
error: Infracost cmd error trace Error: Command failed: cmd /C "set INFRACOST_CLI_PLATFORM=vscode && infracost breakdown --path [object Object] --format json --log-level info"
�[91mError:�[0m No such file or directory [object
Try setting --path to a Terraform plan JSON file. See �[4;1mhttps://infracost.io/troubleshoot�[0m for how to generate this.
For some reason when I run the project in windows it does not work as expected, but if I run in linux it run smoothly.
I have installed the infracost extension and followed the installation instructions. Infracost executable has been added to the path and registered for an API token successfully.
When opening a terraform file in VSCode a pop is shown with the following error
Could not run the infracost cmd in the c:\Users\dwalker\terraform directory. If this is a multi-project workspace please try opening just a single project. If this problem continues please open an issue here: https://github.com/infracost/vscode-infracost.
The Log (Windows) output shows
[2022-06-30 09:39:32.058] [renderer1] [error] [Extension Host] Infracost cmd error trace Error: Command failed: INFRACOST_CLI_PLATFORM=vscode infracost breakdown --path c:\Users\dwalker\terraform --format json --log-level info
'INFRACOST_CLI_PLATFORM' is not recognized as an internal or external command,
operable program or batch file.
If I run the command in Windows cmd I get the same error message but I am able to run the command in Git Bash successfully and see the JSON output for the terraform resources.
Remove the INFRACOST_CLI_PLATFORM
environment variable as it is not mentioned in the infracost docs or refactor the command to be OS agnsotic.
OS: Windows 10
VSCode version: 1.68.1
Infracost version: Infracost v0.10.6
Extension version: 0.1.7
We should configure the extension manifest to work in cloud editors like https://vscode.dev/. We already bundle the Infracost CLI into the manifest, so it should be a matter of allowing for local configuration to be used in the cloud editor to store the API key and config.
Consider the following VSCode workspace:
prod/ # terraform project
dev/ # terraform project
If a user adds a further project to this workspace, e.g. stag
, then the Infracost extension will not show price code lenses on resources within this project. This occurs because this stag
project does not exist in the initial init
run. To fix this, we could run a init
on every file we cannot associate with a project. However, this would be very slow for a user.
Some initial ideas about how we could handle this without impacting speed:
stag
folder is at the same level as other detected projects, e.g. dev
. We would have to somehow exclude module calls from this.breakdown
but avoids all the block computation and price lookup. This could then be safely called for every unassociated file, as it would be quick to run.The Infracost VSCode extension only "activates" in a workspace with Terraform files. This means we don't hog CPU/Mem when users are working on other projects. However, the default "connect to cloud" screen still shows in the Infracost sidebar. This is confusing as the "connect" button won't work as the extension isn't active. We should add a "Open in a Terraform directory or workspace" holding panel to make this clear to users.
Like the title it would be cool to allow the extension to use a self hosted installation of infracost vs purely the SAAS version. This alleviates some of the problem some organizations have where there is an air-gapped network with outbound traffic restricted or proxies for outbound traffic.
Newly created files in a VSCode workspace will not show cost estimates as they are not part of the Infracost cache. We need to hook into VSCode hooks for onDidCreateFiles
and onDidRenameFiles
to pick up new files and file renames. On these actions, we should rebuild the Infracost project cache and associated files.
A workaround for users in the meantime is to close are reopen the workspace in VSCode (not great I know, hopefully this will be fixed ASAP)
Hello,
I'm working with multiple workspaces (with either s3, local or tf cloud backends).
Now I've enabled infracost extension and in vscode I'm getting an error (in the vscode editor):
Could not run the infracost cmd in the /Users/USERNAME/repos/healthscope/Some-Infrastructure directory.
If this is a multi-project workspace please try opening just a single project.
If this problem continues please open an issue here: https://github.com/infracost/vscode-infracost.
It does work on the cli when I specify the workspace though:
$ infracost breakdown --path . --terraform-workspace dev
Evaluating Terraform directory at .
✔ Downloading Terraform modules
✔ Evaluating Terraform directory
✔ Retrieving cloud prices to calculate costs
Project: Some-Infrastructure/some-aws-shakeout-ec2/app1
Workspace: dev
Name Monthly Qty Unit Monthly Cost
aws_alb.application_load_balancer
├─ Application load balancer 730 hours $18.40
└─ Load balancer capacity units Monthly cost depends on usage: $5.84 per LCU
aws_autoscaling_group.asg
└─ aws_launch_template.apptemplate
├─ Instance usage (Linux/UNIX, on-demand, ) 730 hours $0.00
└─ EC2 detailed monitoring 7 metrics $2.10
aws_cloudwatch_metric_alarm.all_alarms["cpu_high"]
└─ High resolution 1 alarm metrics $0.30
aws_cloudwatch_metric_alarm.all_alarms["cpu_low"]
└─ High resolution 1 alarm metrics $0.30
OVERALL TOTAL $21.10
──────────────────────────────────
28 cloud resources were detected:
∙ 4 were estimated, 2 of which include usage-based costs, see https://infracost.io/usage-file
∙ 22 were free, rerun with --show-skipped to see details
∙ 2 are not supported yet, rerun with --show-skipped to see details
Currently got a 'dev' workspace:
$ terraform workspace list
* dev
Why can't you do something like this in the extension to figure out the active workspace?
terraform_workspace="$(command terraform workspace show 2>/dev/null)"
Any way to fix it?
Infracost VSCode extension currently does not support Terragrunt as the Infracost CLI uses a different method to evaluate Terragrunt configuration files. To support Terragrunt, we need to change the evaluation method to hold contextual block information with file names and numbers.
In the interim, we could add partial support for Terragrunt users, where we show cost estimates on Terraform modules that Terragrunt uses.
Note for community
Please 👍 if you'd like to upvote this or receive updates.
Add a comment if you'd like to contribute.
Hi, I've just started using Infracost. So far it is looking good and there are some estimates showing up in my terraform file. However I'm trying to change the currency (to EUR). The documentation mentions to run the infracost
command, however I don't have that installed. I also fail to understand what this command will change to my repository. Is there some file I should add to my repo to change the currency, without having to install the command?
In modules that are used by more than 1 project available in the VSCode workspace the Infracost extension chooses the first price to display over the top of any blocks in the shared module. However, these prices could differ significantly based on share module inputs, e.g. instance_type
being supplied as a variable. We should alter the code lens output to signify to the user that more than one price can be displayed. Prices could be prefixed with the different names of the project calling the module.
Note for community
Please 👍 if you'd like to upvote this or receive updates.
Add a comment if you'd like to contribute.
The project total costs sum up all tree-children, which is incorrect because the tree contains the .tf file and the resources/modules within the same .tf file.
In the screenshot, the google/apps/europe-west1/dev
project should only say “$73.00” instead of “$146.00" (which is just double as the main.tf and the module are child elements of the project).
Resources that solely use usage costs will have a 0.00
cost shown. We should alter the extension to allow users to supply a usage file, or parse it from a known location/name.
It's better that the logic lay within the Infracost CLI. As the VSCode native solution did not detect initialization.
Note for community
Please 👍 if you'd like to upvote this or receive updates.
Add a comment if you'd like to contribute.
Having trouble with the vscode extension. the left sidebar is showing all my directories and their associated costs, but in the editor i am not getting any real time update info, it’s just the normal text editor. i get no pop ups or “total monthly cost” line to click to break down.
vscode version: 1.79.2
infracost extension: v0.2.13
terraform extension v2.26.1
macos 12.6.2
I am seeing errors in the extension debug logs from the terraform extension every time infracost runs an update after I save
errors I am seeing:
2023-06-28 11:57:29.234 [error] [hashicorp.terraform] provider FAILED
2023-06-28 11:57:29.234 [error] Error: main.tf (49,25): position outside of any attribute name, value or block
at /Users/xxx/.vscode/extensions/hashicorp.terraform-2.26.1-darwin-x64/out/extension.js:1:387194
at re (/Users/xxx/.vscode/extensions/hashicorp.terraform-2.26.1-darwin-x64/out/extension.js:1:387488)
at /Users/xxx/.vscode/extensions/hashicorp.terraform-2.26.1-darwin-x64/out/extension.js:1:382272
at Immediate. (/Users/xxx/.vscode/extensions/hashicorp.terraform-2.26.1-darwin-x64/out/extension.js:1:382292)
at process.processImmediate (node:internal/timers:466:21)
after uninstall and reinstall of both infracost and terraform extensions, i am seeing a new error:
2023-06-28 12:05:55.059 [error] [hashicorp.terraform] provider FAILED
2023-06-28 12:05:55.059 [error] Error: no reference origin found
at /Users/xxx/.vscode/extensions/hashicorp.terraform-2.26.1-darwin-x64/out/extension.js:1:387194
at re (/Users/xxx/.vscode/extensions/hashicorp.terraform-2.26.1-darwin-x64/out/extension.js:1:387488)
at /Users/xxx/.vscode/extensions/hashicorp.terraform-2.26.1-darwin-x64/out/extension.js:1:382272
at Immediate. (/Users/xxx/.vscode/extensions/hashicorp.terraform-2.26.1-darwin-x64/out/extension.js:1:382292)
at process.processImmediate (node:internal/timers:466:21)
Dear Infracost community, how are you?
The following error is displayed when I open any TY project:
The Infracost extension requires the Infracost CLI to function. Please install it: https://www.infracost.io/docs/#1-install-infracost.
But:
$ infracost --version
Infracost v0.10.12
$ which infracost
/opt/homebrew/bin/infracost
The brew prefix is different because I am running Infracost in an M1 Pro system, as stated here: https://docs.brew.sh/FAQ#why-is-the-default-installation-prefix-opthomebrew-on-apple-silicon
OS: macOS 12.6 21G115 arm64
Host: MacBookPro18,1
Kernel: 21.6.0
Shell: zsh 5.8.1
CPU: Apple M1 Pro
GPU: Apple M1 Pro
Is there any way I can set the infracost path used by the extension?
Hello
I'm in a company that filters the internet flow behind a web proxy
When I want to make the following order
infracost register
I have an error
Error: Error sending API request: Post "https://dashboard.api.infracost.io/apiKeys?source=cli-register": dial tcp 3.139.172.42:443: i/o timeout
Can you add a functionality to allow to configure the module with a web proxy ?
Sincerely
When a workspace folder contains a space, e.g:
folder/
my folder/ # note space
prod/
dev/
Infracost fails as the path passed to the CLI is not properly escaped, so the above example would fail with:
debug: running Infracost cmd INFRACOST_CLI_PLATFORM=vscode infracost breakdown --path /Users/someuser/folder/my folder --format json --log-level info
error: Infracost cmd error trace Error: Command failed: INFRACOST_CLI_PLATFORM=vscode infracost breakdown --path /Users/someuser/folder/my folder --format json --log-level info
�[91mError:�[0m No such file or directory /Users/someuser/folder/my
Try setting --path to a Terraform plan JSON file. See �[4;1mhttps://infracost.io/troubleshoot�[0m for how to generate this.
�[33mUpdate:�[0m A new version of Infracost is available: �[96mv0.10.6�[0m → �[96mv0.10.7�[0m
$ curl -fsSL https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh | sh
Having 2 projects with the same path will result in only the last one being displayed in the projects overview:
but when running infracost breakdown --config-file infracost.yml
both of them are displayed:
infracost.yml
version: 0.1
projects:
- name: sapbo-prod
path: terraform/sapbo
terraform_var_files:
- ../environments/prod.tfvars
- name: sapbo-dev
path: terraform/layers/sapbo
terraform_var_files:
- ../environments/dev.tfvars
Infracost VSCode has a naive way of offering users the ability to configure Terraform input variables. If terraform var files with the names terraform.tfvars
or *.auto.tfvars
are found, these are used as input files. We should investigate how we can improve this experience for users. Initial thoughts are:
Note for community
Please 👍 if you'd like to upvote this or receive updates.
Add a comment if you'd like to contribute.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.