Infracost VS Code Extension
Infracost's VS Code extension shows you cost estimates for Terraform right in your editor! Prevent costly infrastructure changes before they get into production.
This helps with a few use-cases:
See cost estimates right above their Terraform definitions. Infracost's output updates on file save.
Works with resources and modules
See cost breakdown
If a simple monthly cost isn't enough for you, just click the overview to see a cost breakdown.
Navigate your projects by costs
See a tree overview of your Infrastructure costs. See which projects, files and blocks have the most impact to your budget.
1. Install VS Code extension
Open VS Code and install the Infracost extension.
This will also install the the Hashicorp Terraform extension extension if you don't already have it.
2. Connect VS Code to Infracost
Once you've installed the extension, you'll need to connect to your editor to your Infracost account. Click the "connect to Infracost" button in the Infracost sidebar.
This will open a browser window where you'll be able to log in to Infracost Cloud and authenticate your editor. See the Troubleshooting section if this does not work.
3. Use extension
If you've done the prior steps correctly you'll should now see the Infracost sidebar, showing the costs of the auto-detected Terraform projects within your workspace.
4. Create a Infracost config file
Whilst the Infracost VS Code extension supports auto-detecting projects, this is normally only recommended to get up and running. To get Infracost showing accurate project costs, you'll need to add an Infracost config file at the root of your workspace. This defines the Terraform projects within your workspace and how Infracost should handle them. For example:
You can read more about how the config file works and which fields it supports by reading our dedicated documentation.
When adding a config file to your workspace, it must be placed at the root directory of your workspace, and named either
5. Cost estimates in pull requests
Use our CI/CD integrations to add cost estimates to pull requests. This provides your team with a safety net as people can understand cloud costs upfront, and discuss them as part of your workflow.
The Infracost VS Code extension requires you to have:
How can I supply input variables to Infracost VS Code extension?
To supply input variables for your Terraform projects, we recommend you add a config file. Config files allow you to add any number of variable files for defined projects. Infracost also auto-detects any var files called
Both HCL and JSON var files are supported, JSON var files must include a
How do I supply a usage file to the Infracost VS Code extension?
To supply input variables for your Terraform projects, we recommend you add a config file. Config files allow you to define a usage file for each project you specify, e.g:
I see a lot of resources showing $0.00 costs, why is this?
These resources are likely usage-based resources. For example, AWS Lambda is billed per request, so unless you specify the number of requests that the function receives. You're likely to see a message similar to the following: " Cost depends on usage: $0.20 per 1M requests" in the resource breakdown.
How can I configure the currency Infracost uses?
If you have the
Infracost supports all ISO 4217 currency codes. This FAQ has more details.
Locating Infracost error logs
If you're having problems with the extension and your problem isn't any of the known issues above, you can find the Infracost extension logs using the following method:
The log there might give you more information for a problem you can fix on your own, e.g. syntax errors. If it's something more ominous please raise an issue, so that we can identify and fix the problem. Please include as much of the log information as you can and any other helpful information like OS and VS Code workspace size.
We love any contribution, big or small. If you want to change the Infracost VS Code extension, we recommend you use VS Code to build and develop the extension locally.
Once you're finished with your work, open a PR, and we'll be happy to review it as soon as possible.