rhythmic-camera-22129
02/18/2023, 11:47 PMwhite-airport-8778
# on PR branch
infracost breakdown --path . --format json --out-file infracost-base.json
# on main branch
infracost diff --path . --compare-to infracost-base.json --format json --out-file infracost.json
# The infracost.json is the key file you want
# Log the breakdown format:
infracost output --path infracost.json --format table
# Upload to infracost cloud
infracost upload --path infracost.json
infracost comment
and have the Org Settings > Cost Monitoring Dashboard ticked on, you don’t need to manually run upload
as the comment command does that when the dashboard is enabled.rhythmic-camera-22129
02/19/2023, 12:06 AMwhite-airport-8778
diff
to compare the baseline with the PR branch. The GitLab CI example shows how we use them together to also do a diff: https://gitlab.com/infracost/infracost-gitlab-ci
(this is parsing the HCL code directly, so no need for tf init/plan etc).
let me know if you want to run infracost with a TF plan JSON and I’ll give you slightly different stepsrhythmic-camera-22129
02/19/2023, 12:10 AMwhite-airport-8778
terraform show -json
), then you run
infracost diff --path tf-plan.json --format json --out-file infracost.json
# The infracost.json is the key file you want
# Log the breakdown format:
infracost output --path infracost.json --format table
# Log the diff format:
infracost output --path infracost.json --format diff
# Post an MR comment
infracost comment gitlab --path=infracost.json ...
# Upload to infracost cloud
infracost upload --path infracost.json
rhythmic-camera-22129
02/19/2023, 12:14 AMwhite-airport-8778
infracost diff
command is reading the Terraform plan JSON in my second example aboveinfracost breakdown
is less useful in CI pipelines when you already have a TF plan JSON file, since infracost diff
can read that TF plan JSON file directly and use it to get the baseline from the plan JSON (so no need to run breakdown at all)infracost diff
and it will use that metadata.
If you cat infracost.json
you should see the metadata from the env too.