Infracost's VSCode extension shows you cost estimates for Terraform right in your editor! Prevent costly infrastructure changes before they get into production.
Infracost's extension shows a snapshot of the total cost of resources right above their Terraform definitions. Infracost's output updates on file save. This helps with a few use-cases:
- Compare configs, instance types, regions etc: copy/paste a code block, make changes and compare them.
- Quick cost estimate: write a code block and get a cost estimate without having to use AWS, Google or Azure cost calculators, or read the long/complicated pricing web pages.
- Catch costly typos: if you accidentally type 22 instead of 2 as the instance count, or 1000GB volume size instead of 100, the cost estimate will immediately pick that up and let you know.
Both resource
and module
blocks support showing cost estimates. Infracost's VSCode extension even supports showing prices on 3rd party module blocks!
If a simple monthly cost isn't enough for you, just click the overview to show a detailed breakdown of what components affect the price.
Check out the video below to see the Infracost extension in action!
Infracost.VSCode.extension.mp4
Follow this step to install the Infracost CLI, which is used by this VSCode extension.
Follow this step to get a free API key that's used by the CLI to get prices from our Cloud Pricing API, e.g. get prices for instance types.
- No cloud credentials or secrets are sent to the API and you can also self-host it.
- Infracost does not make any changes to your Terraform state or cloud resources.
Open VSCode and install the Infracost extension.
This will also install the the Hashicorp Terraform extension extension if you don't already have it.
Navigate to any Terraform file, if you've done the prior steps correctly you'll see costs above supported blocks.
The Infracost VSCode extension requires you to have:
- VSCode v1.67.0 or above.
- Infracost CLI version v0.10.6 or above installed and registered with a valid API key.
- The Terraform VSCode extension installed and enabled in VSCode.
To supply input variables for your Terraform projects, you must include a var file called terraform.tfvars
at the root level of your Terraform project.
Alternatively, you can use several files with the suffix *.auto.tfvars
, e.g. dev.auto.tfvars
or prod.auto.tfvars
. Currently, only HCL variable files are supported
you can follow this issue for updates on support for JSON variable files.
To set the currency, run infracost configure set currency EUR
(or any other ISO 4217 currency code). This FAQ has more details.
-
When opening a workspace with a large number of Terraform projects for the first time. Infracost will evaluate all the projects and download any required modules. This means that it might take some time before pricing information is available. If you're worried that Infracost VSCode extension isn't working in your workspace but haven't got any error messages, it is likely that Infracost is still indexing your workspace. The extension has a status bar on the right-hand side of the editor which will show a loading state when Infracost is running.
-
Terragrunt is not supported. Follow this issue for more information for future updates about Terragrunt support.
-
Infracost usage files are not yet supported. This means that resources that solely use usage costs will have a
0.00
cost shown:Follow this issue to receive updates on usage file support.
-
Diff functionality is not yet supported. Follow this issue to receive updates on diff support.
-
VSCode Infracost does not yet work with Infracost config files. Multi project support is available using Infracost native auto-detection. This means that the first time running in a multi-project workspace might be quite slow. Follow this issue to receive updates on config file support.
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:
- Open the extension terminal using the top menu (Terminal->New Terminal)
- Select Output and Infracost Debug from the dropdown.
- There are sometimes additional CLI logs hidden in the log (Window) output.
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 VSCode workspace size.
We love any contribution, big or small. If you want to change the Infracost VSCode extension, we recommend you use VSCode to build and develop the extension locally.
- Clone the repo.
yarn
install all the dependencies.- Open the repo in VSCode.
- Install the Terraform VSCode extension in VSCode.
- Inside the editor, press F5. VSCode will compile and run the extension in a new Development Host window.
- Open a Terraform project, and navigate to a valid file. If all the previous steps have been followed correctly, you should see Infracost cost estimates above supported resource blocks.
Once you're finished with your work, open a PR, and we'll be happy to review it as soon as possible.