v0.10.0
What's new?
Back in February 2022, we started an experiment to estimate costs by parsing Terraform HCL code directly. We're excited to announce that the experiment worked! So in v0.10 we've removed the experimental --terraform-parse-hcl
flag and made HCL parsing the default behavior.
Going forward, we'll support two ways to run Infracost with Terraform via --path
:
- Parsing HCL code (directory): this is the default and recommended option as it has the following 5 key benefits.
# Terraform variables can be set using --terraform-var-file or --terraform-var infracost breakdown --path /code
- Parsing plan JSON file: this will continue to work as before.
cd /code terraform init terraform plan -out tfplan.binary terraform show -json tfplan.binary > plan.json infracost breakdown --path plan.json
1. Faster CLI
Infracost can now generate cost estimates without needing a Terraform plan. This removes our dependency on the Terraform binary altogether, which means no more terraform init
or terraform plan
.
That, in turn, means a super-fast CLI: Infracost used to take around 50 seconds to run on our internal Terraform mono-repo, that's now reduced to 2 seconds. 🚀
2. No cloud creds needed
Running terraform plan
requires users to have cloud credentials and Terraform secrets. The main reason we created the Infracost CLI first, instead of a web API, was so it could parse the Terraform plan JSON locally to extract cost-related parameters (e.g. instance type). Thus credentials and secrets were not sent anywhere.
Whilst this worked and was safe, it still posed a question: is there a way to avoid setting credentials or secrets altogether? Removing our dependency on terraform plan
gave us a way to do that.
3. Cost estimates everywhere
Not needing cloud credentials, or even knowledge of how to generate a Terraform plan, means that any engineer who has access to code repos can generate cost estimates!
This also opens the door for cost estimates to be put everywhere: Infra-as-Code repo readmes, Terraform module readmes, Visual Studio, and even in continuous integration systems where a Terraform plan does not exist (not everyone runs Terraform via continuous deployment systems).
To make infracost diff
work without a Terraform plan, we introduced a new --compare-to infracost-base.json
flag. This enables a git-based cost diff to be produced, e.g.:
git checkout main
infracost breakdown --path /code --format json --out-file infracost-base.json
git checkout my-branch
infracost diff --path /code --compare-to infracost-base.json
4. Compare Infracost runs
The infracost diff
command can now also be used to compare Infracost runs. Assuming you generated the files infracost-last-week.json
and infracost-today.json
using the infracost breakdown --path /code --format json
command, you can compare them using:
infracost diff --path infracost-today.json --compare-to infracost-last-week.json
5. Detect multi-project repos
Setting the --path
flag to a top-level repo directory will now attempt to process all projects automatically by:
- Looking at the specified path or in any of the subdirectories with a depth less than 5.
- Processing Terraform variable files with the
.auto.tfvars
extension (similar to what Terraform does). - Processing environment variables with a
TF_VAR_
prefix (similar to what Terraform does).
If this does not work for your use-case, use a config-file and run infracost breakdown --config-file=infracost.yml
, for example:
# infracost.yml
version: 0.1
projects:
- path: prod
terraform_var_files:
- prod.tfvars
- us-east.tfvars
- path: dev
terraform_var_files:
- dev.tfvars
Migration guides
👉👉👉 See the migration guides in the docs for migrating specific CI systems to use the new v0.10 Infracost version.
Removed functionality
See this docs section.
Known issues
See this docs section.
Other changes
New resources
- Support for
google_compute_per_instance_config
by @golgeek in #1645 - Support for
google_compute_region_per_instance_config
by @golgeek in #1657
AWS
- Support for reservation in
db_instance
by @carmeloriolo in #1653
Enhancements
- Add a better error message for errors originating from the Terragrunt libs by @aliscott in #1666
- Add breakdown path hint by @tim775 in #1673
- Fallback to the workspace defined by TF env for remote var loading by @hugorut in #1679
- Enable
-no-color
option by default for CI by @vdmgolub in #1628
Fixes
- Redis instance monthly pricing by @vdmgolub in #1627
- Mark azure b1 type machine as free by @tim775 in #1629
- Resolve SNS Topic notification price filters by @vdmgolub in #1633
- Solve support for references with for_each by @golgeek in #1640
- Rework reference mapping by @golgeek in #1660
- Computation of local scratch disk in GCP by @golgeek in #1655
- MSSQL Database License Type retrieval by @vdmgolub in #1664
- Update GCE inter-region egress filter by @tim775 in #1674
- Show only one cost component for Google Compute Address by @vdmgolub in #1639
New Contributors
- @golgeek made their first contribution in #1640
- @carmeloriolo made their first contribution in #1653
We also want to give a massive thank you to every community member who has helped us with any HCL parsing issues by reporting them and helping us reproduce them. Finding these issues would not have been possible without this 🎉.