Skip to content

Latest commit

 

History

History
182 lines (119 loc) · 10 KB

README.md

File metadata and controls

182 lines (119 loc) · 10 KB

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:

  • 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.

Features

See cost estimates right above their Terraform definitions. Infracost's output updates on file save.

Works with resources and modules

Both resource and module blocks are supported. 3rd party module blocks are also supported!

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.

Get started

1. Install VS Code extension

Open VS Code and install the Infracost extension.

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:

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.

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.

Requirements

The Infracost VS Code extension requires you to have:

FAQs

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

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:

version: 0.1
projects:
  - path: dev
    usage_file: dev/infracost-usage.yml
  - path: prod
    usage_file: prod/infracost-usage.yml

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.

To specify usage for resources, add a usage file and reference it in a config file you add at the root of your workspace.

How can I configure the currency Infracost uses?

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.

Troubleshooting

Known Issues

  • 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:

    1. 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.
    2. Install the infracost CLI.
    3. Run infracost configure set api_key MY_API_KEY_HERE.
    4. Re-open the VSCode extension, it should now skip the "connect to Infracost" step as it uses the same API key from the CLI.

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:

  1. Open the extension terminal using the top menu (Terminal->New Terminal)
  2. Select Output and Infracost Debug from the dropdown.
  3. 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.

Contributing

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.

  1. Clone the repo.
  2. yarn install all the dependencies.
  3. Open the repo in VS Code.
  4. Inside the editor, press F5. VS Code will compile and run the extension in a new Development Host window.
  5. 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.