victorious-artist-11969
08/26/2024, 1:06 PMtfplan.json
) shows changes in resources, but when I run infracost diff
, the resulting diff.json
doesn't show any differences in costs. Here's a summary of my setup and what I've tried so far:
1. Baseline: I have a baseline file (infracost.json
) that I download from an S3 bucket.
2. Terraform Plan: I generate the Terraform plan and convert it to JSON using terraform show -json
to create tfplan.json
.
3. Ignored Resources: I have a list of resource types that I ignore (e.g., aws_security_group
, null_resource
, etc.).
4. Commands:
When I have a baseline, I run:
infracost diff --show-skipped --path <path_to_tfplan.json> --compare-to <path_to_infracost.json> --format json --out-file diff.json
If no baseline is found, I run:
infracost breakdown --show-skipped --path <path_to_tfplan.json> --format json --out-file breakdown.json
Problem: Despite the tfplan.json
file showing resource changes that should affect costs, the diff.json
output does not show any differences in cost. I have double-checked that both the baseline and plan files are correct and reflect the expected state.
Questions:
1. What could cause infracost diff
to not show any cost changes even when the Terraform plan (tfplan.json
) indicates resource changes? (I've added aws rds instance as new resource)
2. Are there specific resource types or changes that infracost
might not detect as cost-impacting?
3. Could there be any issues with how the baseline is set or formatted that would cause infracost diff
to fail to detect changes?
4. Any other debugging steps or logging options I should enable to better understand why infracost diff
isn’t reflecting the plan changes?
I would appreciate any insights or suggestions on how to resolve this!
Thank you!little-author-61621
infracost diff
directly against it instead of using a baseline. Since the plan JSON file already has the state in it, Infracost shouldn’t need a baseline.
See here for an example: https://www.infracost.io/docs/features/cli_commands/#option-2-terraform-plan-json-1victorious-artist-11969
08/26/2024, 3:24 PMterraform plan
, we generate *.tfplan.json
files for all resources.
• Using a Bash loop, we run infracost breakdown
for each plan file to create a detailed cost breakdown:
infracost breakdown --show-skipped --path plan_file --format json --out-file /infracost/diffs/infracost-breakdown-${plan_name}.json
◦ These breakdowns are uploaded to S3 as our "master" baseline for the project.
1. Handling New Changes:
◦ When we add new resources, such as an AWS RDS instance, we run terraform plan
again to generate updated plan files.
• We then download the "master" baseline from S3 and use infracost diff
to compare the new plan files with the baseline:
infracost diff --show-skipped --path $tf_plan --compare-to baseline.json --format json --out-file diffs/infracost-diff-${plan_name}.json
◦ This process produces several infracost-diff-*
files, as we have multiple pipelines with different resources.
• Finally, we merge these diff files and post them as comments on the GitLab PR:
infracost output --path /infracost/diffs/* --format json --out-file infracost-diff.json
infracost comment gitlab --path=infracost-diff.json --behavior=update
1. The Issue:
◦ We’re seeing cases where new resources, like an AWS RDS instance, do not appear in the Infracost output, and it reports 0 changes in infrastructure costs.
Could you help us understand why this might be happening or if there’s anything we need to adjust in our approach?little-author-61621
infracost diff --show-skipped --path $tf_plan --format json --out-file diffs/infracost-diff-${plan_name}.json
victorious-artist-11969
08/26/2024, 3:42 PMinfracost breakdown
to create an initial baseline.json
. This baseline captures the cost state of all existing resources in the Terraform project at the start.
For any subsequent changes (e.g., adding new resources), we run infracost diff
to compare the new *.tfplan.json
files against this baseline.json
. This helps us understand the cost impact of the changes relative to the initial setup.
After the initial comparison, we update the baseline to reflect the latest state by using the output from infracost diff
. This updated baseline is then used for future comparisons.
In essence, we use infracost breakdown
to establish the starting point, and then infracost diff
to track and update changes, ensuring that our baseline remains current and accurately reflects the cost state of the infrastructure.
Is there a more efficient approach to managing and updating the baseline, or any best practices we should follow to ensure we are capturing cost changes accurately?
Thank you for your assistance!little-author-61621
infracost diff
is run against the plan it automatically uses the state within the plan as the baseline.white-airport-8778
victorious-artist-11969
08/27/2024, 6:59 AMinfracost breakdown
command if infracost diff
can automatically use the state within the tfplan.json
as the baseline? When should we use infracost breakdown
instead of infracost diff
?victorious-artist-11969
08/27/2024, 1:45 PMwhite-airport-8778
infracost diff
in the CI/CD pipeline.
breakdown
is useful when parsing Terraform HCL.
Re your second question: it’s hard to debug from that message as I don’t know what’s in the plan JSON file. Like we mentioned before, the majority of users use the Terraform HCL parsing option so the baseline will show whatever is on the default branch in PRs.victorious-artist-11969
08/27/2024, 3:34 PMinfracost diff
for all of my tfplan.json
files. After that, I merge the results using infracost output
and add comments with infracost comment gitlab
.
I have a few questions regarding how the costs are calculated:
1. I've added a new resource, an AWS RDS instance, which is not yet applied; it only exists in the plan JSON. Initially, Infracost shows one baseline cost, but after I change the instance size from xlarge
to 2xlarge
, the baseline cost changes. Could you explain why the baseline cost changes in this case?
2. How are the "New monthly costs" calculated? When I add the baseline cost and usage cost, the sum does not match the total that Infracost calculates in the pull request.
Could you please help me understand these calculations?
Thank you!victorious-artist-11969
08/28/2024, 8:20 AMwhite-airport-8778
victorious-artist-11969
08/30/2024, 7:13 AMinfracost breakdown
?