🙌 Thank you for contributing and joining our mission to help engineers use cloud infrastructure economically and efficiently 🚀.
Join our community Slack channel, we are a friendly bunch and happy to help you get started :)
The overall process for contributing to Infracost is:
- Check the project board to see if there is something you'd like to work on; these are the issues we'd like to focus on in the near future. The issue labels should help you to find an issue to work on. There are also other issues and discussions that you might like to check.
- Create a new issue if there's no issue for what you want to work on. Please put as much as details as you think is necessary, the use-case context is especially helpful if you'd like to receive good feedback.
- Add a comment to the issue you're working on to let the rest of the community know.
- Create a fork, commit and push to your fork. Send a pull request (PR) from your fork to this repo with the proposed change. Don't forget to run
make lint
andmake fmt
first. Please include unit and integration tests where applicable. We use Conventional Commits. Commit messages can usually start with "feat(aws): add ...", "feat(google): add ...", "fix: nil pointer...", "docs: explain...", or "chore: fix typo". This helps us generate a cleaner changelog. - If it's your first PR to the Infracost org, a bot will leave a comment asking you to follow a quick step to sign our Contributor License Agreement.
- We'll review your change and provide feedback.
This guide assumes you are familiar with Terraform, if not you can take an hour to read/watch this and this.
Assuming you have already installed go, install the go dependencies
make deps
Run the code:
make run ARGS="breakdown --path examples/terraform --usage-file=examples/terraform/infracost-usage.yml"
This will use your existing Infracost API key; register for a free API key key if you don't have one already.
To run only the unit tests:
make test
You should run tests with the -v
flag and warn log level so you can see and fix any warnings:
INFRACOST_LOG_LEVEL=warn go test -v -cover ./internal/providers/terraform/aws/ebs_volume_test.go
time="2021-04-05T15:24:16Z" level=warning msg="Multiple prices found for aws_ebs_volume.gp3 Provisioned throughput, using the first price"
To run all the tests for a specific cloud vendor:
make test_aws
make test_google
make test_azure
To run all the tests, you can use:
make test_all
Test golden files may be updated for all test or for a specific cloud vendor:
make test_update
make test_update_aws
make test_update_google
make test_update_azure # see the Azure credentials section below
make build
Checkout our dedicated guide to add resources!
Working on Azure resources requires Azure creds as the Azure Terraform provider requires real credentials to be able to run terraform plan
. This means you must have Azure credentials for running the Infracost commands and integration tests for Azure. We recommend creating read-only Azure credentials for this purpose. If you have an Azure subscription, you can do this by running the az
command line:
az ad sp create-for-rbac --name http://InfracostReadOnly --role Reader --scope=/subscriptions/<SUBSCRIPTION ID> --years=10
If you do not have an Azure subscription, then please ask on the contributors channel on the Infracost Slack and we can provide you with credentials.
To run the Azure integration tests in the GitHub action in pull requests, these credentials also need to be added to your fork's secrets. To do this:
- Go to
https://github.com/<YOUR GITHUB NAME>/infracost/settings/secrets/actions
. - Add repository secrets for
ARM_SUBSCRIPTION_ID
,ARM_TENANT_ID
,ARM_CLIENT_ID
andARM_CLIENT_SECRET
.
- Use a browser extension like modheader to allow you to specify additional headers in your browser.
- Go to https://pricing.api.infracost.io/graphql
- Set your
X-API-Key
using the browser extension - Run GraphQL queries to find the correct products. Examples can be found here: https://github.com/infracost/cloud-pricing-api/tree/master/examples/queries
The GraphQL pricing API limits the number of results returned to 1000, which can limit its usefulness for exploring the data. AWS use many acronyms so be sure to search for those too, e.g. "ES" returns "AmazonES" for ElasticSearch.
Here is a list of things we should look for during code review when adding new resources:
- Is the infracost-usage-example.yml file updated with any new usage file parameters and descriptions?
- Some common bugs that are discovered in reviews:
- case sensitive string comparisons:
d.Get("kind") ==
should bestrings.ToLower(d.Get("kind").String()) ==
- case sensitive regex in price filters:
ValueRegex: strPtr(fmt.Sprintf("/%s/", deviceType))
should beValueRegex: strPtr(fmt.Sprintf("/%s/i", deviceType))
- missing anchors in price filter regex:
fmt.Sprintf("/%s/", x)
when it should befmt.Sprintf("/^%s$/", x)
- incorrect output capitalization: └─ Data Ingested should be └─ Data ingested
- misnamed unit:
GB-month
should beGB
- case sensitive string comparisons:
- Any "Missing prices" or "Multiple prices" lines when running with
--log-level debug
? - Any incorrect prices or calculations?
- Any docs pages need to be updated? e.g. the supported resources pages. If so, please open a PR so it can be merged after the CLI is released.