Project: Infracost (Observability and Analysis / Continuous Optimization)
File: CONTRIBUTING.md

Thank you for contributing and joining our mission to help engineers use cloud infrastructure economically and efficiently . , we are a friendly bunch and happy to help you get started :) - - - - - The overall process for contributing to Infracost is: Check the 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 and 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` and `make fmt` first. Please include unit and integration tests where applicable. We use . 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 and . Assuming you have already , install the go dependencies ```sh make deps ``` Run the code: ```sh 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 key if you don't have one already. To run only the unit tests: ```sh make test ``` You should run tests with the `-v` flag and warn log level so you can see and fix any warnings: ```sh INFRACOSTLOGLEVEL=warn go test -v -cover ./internal/providers/terraform/aws/ebsvolumetest.go time="2021-04-05T15:24:16Z" level=warning msg="Multiple prices found for awsebsvolume.gp3 Provisioned throughput, using the first price" ``` To run all the tests for a specific cloud vendor: ```sh make test_aws make test_google make test_azure ``` To run all the tests, you can use: ```sh make test_all ``` Test golden files may be updated for all test or for a specific cloud vendor: ```sh make test_update make testupdateaws make testupdategoogle make

# see the Azure credentials section below ``` ```sh make build ``` Checkout 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: ```sh 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 `ARMSUBSCRIPTIONID`, `ARMTENANTID`, `ARMCLIENTID` and `ARMCLIENTSECRET`. Use a browser extension like 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://www.infracost.io/docs/supportedresources/cloudpricing_api/ 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. Consult as an example. In , add the new region's information to `RegionMapping`, `RegionCodeMapping`, and `RegionsUsage` as needed. In , update `regionCodeMapping` as needed. In , update `regionShieldMapping` as needed. In , add a usage block for data transfer. Update by running `ARGS="-run TestDataTransferGoldenFile -v -update" make test_aws`. Update [internal/hcl/zones_aws.go]: Use the AWS CLI to check if the region is enabled in your AWS account by running `aws ec2 describe-availability-zones --region <NEW-REGION_ID e.g. ca-west-1>` If needed, enable the region by running `aws account enable-region --region-name <NEW-REGION-ID>`. This usually takes several minutes. From the `internal/hcl` directory, run `go run ../../tools/describezones/main.go aws`. Here is a list of things we should look for during code review when adding new resources: Is the 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 be `strings.ToLower(d.Get("kind").String()) ==` case sensitive regex in price filters: `ValueRegex: strPtr(fmt.Sprintf("/%s/", deviceType))` should be `ValueRegex: strPtr(fmt.Sprintf("/%s/i", deviceType))` missing anchors in price filter regex: `fmt.Sprintf("/%s/", x)` when it should be `fmt.Sprintf("/^%s$/", x)` incorrect output capitalization: Data Ingested should be Data ingested misnamed unit: `GB-month` should be `GB` Any "Missing prices" or "Multiple prices" lines when running with `--log-level debug`? Any incorrect prices or calculations? Any pages need to be updated? e.g. the pages. If so, please open a PR so it can be merged after the CLI is released.