rhythmic-camera-2212902/18/2023, 11:47 PM
# 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
and have the Org Settings > Cost Monitoring Dashboard ticked on, you don’t need to manually run
as the comment command does that when the dashboard is enabled.
rhythmic-camera-2212902/19/2023, 12:06 AM
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 steps
rhythmic-camera-2212902/19/2023, 12:10 AM
), then you run
terraform show -json
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-2212902/19/2023, 12:14 AM
command is reading the Terraform plan JSON in my second example above
is less useful in CI pipelines when you already have a TF plan JSON file, since
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)
and it will use that metadata. If you
you should see the metadata from the env too.