v0.10 migration guide
Once you've installed Infracost v0.10, follow this page to migrate. If you run into any issues, please join our community Slack channel or create an issue, we'll help you very quickly 😄
What's new?​
Back in February, we started an ambitious journey: remove our dependency on the Terraform CLI by parsing code directly! Infracost v0.10 completes that journey 🎉
Infracost is now much faster, simpler to add to CI/CD, and does not need cloud creds since a plan is not required.
The experimental --terraform-parse-hcl
flag has been removed and going forward, Infracost can be run in two ways via --path
:
Parsing HCL code (directory): 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 /codeParsing 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 CLI altogether, which means no more terraform init
and 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​
Removing our dependency on the Terraform CLI means you no longer need to set cloud credentials or Terraform secrets, which simplifies CI/CD integrations too.
3. Cost of TF modules​
Not needing cloud creds/secrets or a Terraform plan means you can now generate cost estimates from Terraform modules. It also enables cost estimates to be put in Infra-as-Code repo readmes and Visual Studio!
To make infracost diff
work without a plan, we introduced a new --compare-to
flag so git-based cost diffs can be produced:
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 to see what's changed between historic runs:
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
Removed functionality​
If you previously used the following two options to see the cost breakdown of the current Terraform state, you can now just run infracost breakdown --path /code
against the already-deployed branch.
- The
--terraform-use-state
flag has been removed. - Running Infracost against a Terraform state JSON file is no longer supported.
If you previously ran Infracost with a Terraform plan binary file, you should now generate a plan JSON file and use that instead:
terraform plan -out tfplan.binary
terraform show -json tfplan.binary > plan.json
infracost breakdown --path plan.json
If you previously used the INFRACOST_TERRAGRUNT_FLAGS
environment variable, you can now use --exclude-path
with breakdown
and diff
:
infracost breakdown --path=. --exclude-path=dev --exclude-path=test
Known issues​
There are known issues with Terragrunt, and some Terraform users. However, there are workarounds you can use to unblock yourself and continue to upgrade to v0.10.
Migrations guides​
We've also updated our Jenkins, Bitbucket and CircleCI examples.
Generic migration guide (if you can't use the above guides)
Option 1: Terraform directory (recommended)​
Parsing HCL has no concept of Terraform state. This makes it super-fast, but this means you'll need to compare Infracost runs to show cost differences.
For example, the following v0.9 commands:
cd /code
# Checkout your feature branch
git checkout my-branch
# Generate Infracost JSON file, this internally invoked the
# Terraform CLI to create a plan JSON that was used by Infracost.
infracost breakdown --path . \
--format json --out-file infracost.json
infracost comment github --path infracost.json ...
Needs to be rewritten as such in v0.10:
cd /code
# Generate Infracost JSON file as the baseline.
# Terraform variables can be set using --terraform-var-file or --terraform-var
git checkout main
infracost breakdown --path . \
--format json --out-file infracost-base.json
# Generate a diff by comparing the latest code change with the baseline
git checkout my-branch
infracost diff --path . \
--compare-to infracost-base.json \
--format json --out-file infracost.json
infracost comment github --path infracost.json ...
Option 2: Terraform plan JSON​
If you already use Infracost with a Terraform plan JSON, you don't need to change anything as that will continue to work (since the Infracost --path
flag detects a Terraform plan JSON).
If you were used to running Infracost against a Terraform project directory, and want the old behavior where Infracost invoked the Terraform CLI, you can manually generate a plan JSON and use that instead:
cd /code
terraform init
terraform plan -out tfplan.binary
terraform show -json tfplan.binary > plan.json
infracost breakdown --path plan.json \
--format json --out-file infracost.json
infracost comment github --path infracost.json ...