• Stars
    star
    1,789
  • Rank 25,371 (Top 0.6 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created about 2 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

See cost estimates for Terraform right in your editor๐Ÿ’ฐ๐Ÿ“‰

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.

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:

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. Install the Terraform VS Code extension in VS Code.
  5. Inside the editor, press F5. VS Code will compile and run the extension in a new Development Host window.
  6. 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.

More Repositories

1

infracost

Cloud cost estimates for Terraform in pull requests๐Ÿ’ฐ๐Ÿ“‰ Shift FinOps Left!
Go
10,381
star
2

cloud-pricing-api

GraphQL API for cloud pricing. Contains over 3M public prices from AWS, Azure and GCP. Self-updates prices via an automated weekly job.
TypeScript
348
star
3

actions

GitHub Action for Infracost. See cloud cost estimates for Terraform in pull requests. ๐Ÿ’ฐ๐Ÿ“‰ Love your cloud bill!
JavaScript
211
star
4

infracost-atlantis

Atlantis integration for Infracost. Shows cloud cost estimates for Terraform in pull requests.
Dockerfile
127
star
5

infracost-gh-action

GitHub Action for Infracost. Shows cloud cost estimates for Terraform in pull requests.
120
star
6

helm-charts

Official Infracost Helm charts
Smarty
29
star
7

compost

Post pull request comments from multiple CI platforms
TypeScript
29
star
8

infracost-azure-devops

Azure DevOps integration for Infracost. Shows cloud cost estimates for Terraform in pull requests for Azure DevOps repos and GitHub repos.
TypeScript
29
star
9

terraform-provider-infracost

This repo is deprecated, please use the https://infracost.io/usage-file/ instead.
Go
20
star
10

infracost-jenkins

Jenkins integration for Infracost. Shows cloud cost estimates for Terraform.
19
star
11

docs

Infracost docs
JavaScript
12
star
12

infracost-orb

CircleCI Orb for Infracost. Shows cloud cost estimates for Terraform in GitHub and BitBucket pull requests.
11
star
13

gh-actions-demo

Demo repo for Infracost GitHub Action
HCL
10
star
14

docusaurus-plugin-plausible

Docusaurus plugin for Plausible analytics
JavaScript
9
star
15

infracost-circleci

Atlantis integration for Bitbucket. Shows cloud cost estimates for Terraform in pull requests.
8
star
16

example-terraform

Example Terraform project
HCL
6
star
17

setup-infracost

Use https://github.com/infracost/actions
TypeScript
4
star
18

compost-action

Post pull request comments from multiple CI platforms
TypeScript
4
star
19

atlantis-demo

Demo repo for Infracost Atlantis integration
HCL
4
star
20

circleci-github-demo

Demo repo for Infracost running in CircleCI with GitHub
HCL
3
star
21

compost-go

Post pull request comments to multiple VCSs
Go
3
star
22

compost-e2e-tests-template

Testing repo for Compost E2E tests
2
star
23

infracost-gitlab-ci

GitLab CI examples for Infracost. Shows cloud cost estimates for Terraform in GitLab merge requests
2
star
24

cross-account-link

A Terraform module to set up an AWS cross-account link for Infracost Cloud.
HCL
1
star
25

jenkins-demo

Demo repo for Infracost running in Jenkins
HCL
1
star
26

compost-e2e-tests

Compost E2E test repo
1
star
27

azure-devops-github-demo

Demo repo for Infracost Azure DevOps integration
HCL
1
star
28

demo-repo

Demo repo for Infracost Cloud
HCL
1
star