Repository navigation
fix(infracost): sum the cost of every project, not only the first - #418
Open
MahediBuilds wants to merge 1 commit into
Open
MahediBuilds wants to merge 1 commit into
MahediBuilds wants to merge 1 commit into
Conversation
The `return` in both cost helpers sat inside the loop over `projects`, so only the first project's resources were ever summed. Infracost writes one project per Terraform directory, so a cost limit passed whenever the expensive directory was not listed first, and a `resource_type` living in a later project was reported as 0 resources costing 0.
MahediBuilds
requested review from
Akshat0694,
arunim2405 and
refeed
as code owners
October 23, 2026 15:52
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Template
Description
What changes are being made?
projects[].breakdown.resources[]across every project. Thereturnin__get_all_costsand__get_resources_costswas inside thefor project in input_data["projects"]loop, so it returned after the first project.Why are these changes necessary?
infracost breakdownwrites one project per Terraform directory, so a cost limit is only as good as the order of the projects. With a $10 project followed by a $5,000 one, this policy passed onmain:{"operation_type": "total_monthly_cost", "resource_type": ["*"]} {"type": "LessThanEqualTo", "value": 1000}Filtering on a
resource_typethat only exists in a later project reported0 resourcesand a cost of0, which also passes aLessThanlimit.Which issues or tickets does this PR close or relate to?
documentation/docs/tirith-providers/infracost.mddescribed the behaviour ("only the first project in theprojectsarray is summed"); that note is replaced.Type of Change
Checklist
Screenshots or Recordings (if applicable)
N/A
Additional Information
Testing.
tests/providers/infracost/test_infracost_multiple_projects.pyadds three tests; all three fail onmainand pass with this change.The 24 failures are the same 24 that fail on
mainon my machine (Windows):test_direct_references,test_discover,test_policyfiles,test_ui_cli,test_archiveand one intest_policy_parameterization, all on temp-dir or path-separator handling. None touch infracost.black --checkwith the pinned 25.1.0 is clean on both changed Python files.Docs.
documentation/scripts/generate-llms-full.pyfails on Windows (it compares backslash paths againstORDER), so I applied the same one-line change tostatic/docs/.../infracost-provider.mdandstatic/llms-full.txtby hand. Re-running the script on Linux should produce no diff, but worth a check.Behaviour change to be aware of. Policies whose costs were spread over several projects will now see the real total, so some that passed will fail. That is the fix, but it may deserve a changelog line. Two smaller consequences of the same change:
breakdown.resourcesnow raises the existingbreakdown/resources not found in one of the projecterror instead of being ignored."projects": []now returns a cost of 0 with0 resources, where it used to crash withTypeError: cannot unpack non-iterable NoneType object.