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:
- 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, Azure or Google 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.
See cost estimates right above their Terraform definitions. Infracost's output updates on file save.
Both resource
and module
blocks are supported. 3rd party module blocks are also supported!
If a simple monthly cost isn't enough for you, just click the overview to see a cost breakdown.
See a tree overview of your Infrastructure costs. See which projects, files and blocks have the most impact to your budget.
Open VS Code and install the Infracost extension.
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.
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.
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:
version: 0.1
projects:
- path: dev
name: development
usage_file: dev/infracost-usage.yml
terraform_var_files:
- dev.tfvars
- path: prod
name: production
usage_file: prod/infracost-usage.yml
terraform_vars:
instance_count: 5
artifact_version: foobar
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 infracost.yml
for a static config file or infracost.yml.tmpl
for a dynamic config files.
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:
- VS Code v1.67.0 or above.
- The Terraform VS Code extension installed and enabled in VS Code.
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 terraform.tfvars
, or *.auto.tfvars
at the root level of your Terraform projects. e.g:
version: 0.1
projects:
- path: dev
name: development
usage_file: dev/infracost-usage.yml
terraform_var_files:
- dev.tfvars
- global.tfvars
Both HCL and JSON var files are supported, JSON var files must include a .json
suffix.
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:
version: 0.1
projects:
- path: dev
usage_file: dev/infracost-usage.yml
- path: prod
usage_file: prod/infracost-usage.yml
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.
To specify usage for resources, add a usage file and reference it in a config file you add at the root of your workspace.
If you have the infracost
CLI installed, you can set the currency by running infracost configure set currency EUR
(check infracost configure --help
for other configuration options). Otherwise, update the global infracost configuration file (found at ~/.config/infracost/configuration.yml
) with the following:
version: "0.1"
currency: EUR
Infracost supports all ISO 4217 currency codes. This FAQ has more details.
-
The extension is not designed to work in the context of a multi-repo workspace. We recommend opening one repo per workspace.
-
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 VS Code 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.
-
Diff functionality is not yet supported. Follow this issue to receive updates on diff support.
-
If the "Connect VSCode to Infracost" button does not work:
- Register for a free API key from here. This is used by the extension to retrieve prices from our Cloud Pricing API, e.g. get prices for instance types.
- Install the
infracost
CLI. - Run
infracost configure set api_key MY_API_KEY_HERE
. - Re-open the VSCode extension, it should now skip the "connect to Infracost" step as it uses the same API key from the CLI.
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 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.
- Clone the repo.
yarn
install all the dependencies.- Open the repo in VS Code.
- Inside the editor, press F5. VS Code 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.