Repository navigation
fix(autodetect): stop dropping nested non-Terraform projects - #28
Closed
liamcervante wants to merge 1 commit into
Closed
liamcervante wants to merge 1 commit into
liamcervante wants to merge 1 commit into
Conversation
The final filter in filterProjects dropped any non-Terraform project that had a project ancestor. Nesting is the normal, correct layout for several formats - a Kustomize app directory holds base/ and overlays/ subdirectories that are themselves kustomization directories - so this discarded projects that should have been detected. The effect is worst in a GitOps repository that keeps a controller manifest in its root, pointing at the manifests held elsewhere in the tree. That root directory is a Kubernetes project in its own right, so every project in the repository has a project ancestor and all of them are dropped, collapsing the repository to its root - which is read non-recursively and yields nothing. The filter's documented purpose is narrower than its condition: a CloudFormation template inside a Terraform project is usually deployed by that Terraform via aws_cloudformation_stack, so emitting it standalone represents one deployment twice. Check for that case specifically. Where a parent genuinely owns its nested directories, the parent's IdentifyEnvironments answer already claims them, which suppresses them precisely rather than by proximity. This also restores nesting for ARM and Cisco Stacks projects, which the blanket condition dropped for the same reason. IsInsideProject had no other callers and is replaced by the narrower IsInsideTerraformProject.
liamcervante
marked this pull request as ready for review
August 17, 2026 10:34
Contributor
Author
|
#29 does this but better |
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.
Problem
The final filter in
filterProjectsdropped any non-Terraform project that had a project ancestor:Nesting is the normal, correct layout for several formats — a Kustomize app directory holds
base/andoverlays/subdirectories that are themselves kustomization directories — so this discarded projects that should have been detected.The effect is worst in a GitOps repository that keeps a controller manifest in its root (an Argo CD
Application, say) pointing at the manifests held elsewhere in the tree. That manifest carries top-levelapiVersion+kind, so the root directory is a Kubernetes project in its own right. Every project in the repository then has a project ancestor, so all of them are dropped and the repository collapses to.— whichParseDirToTreereads non-recursively, yielding nothing. A repository of ~1800 Kustomize directories reports one project and zero resources.Fix
The comment above that filter describes something much narrower than the condition implements: "remove cfn projects that lie within a tf/tg project". That case is real — a CloudFormation template inside a Terraform project is usually deployed by that Terraform via
aws_cloudformation_stack, so emitting it standalone represents one deployment twice. So check for it specifically:Where a parent genuinely owns its nested directories, the parent's
IdentifyEnvironmentsanswer already claims them (claimedDirsinexpandProjects), which suppresses them precisely instead of by proximity. That mechanism is two-pass and order-independent, so it does this job without help from the proximity filter.IsInsideProjecthad no other callers and is replaced by the narrowerIsInsideTerraformProject.Blast radius
Beyond Kubernetes, the blanket condition was also dropping nested ARM and Cisco Stacks projects for the same wrong reason. Those now nest too. Repositories with such layouts will gain projects they should have had, so it is worth a look at runner golden output before this ships.
Testing
generate_nesting_with_plugins_test.godrives real files on disk throughconfig.Generatewith the released parser plugins, so identification and environment expansion are exercised end to end rather than mocked:base/andoverlays/dev/, and a directory of controller manifests. Asserts three projects: the root,app-devatapp/overlays/devwithapp/base/**as a dependency path, andwrappers. Noteapp/baseandapp/overlays/devare correctly absent, suppressed by the app's claimed directories.Against the old condition the first test reports
expected 3 projects, got 1, reproducing the production failure exactly — verified by reinstating it, so the test is not vacuous.infracost-parser-kubernetesis added to the downloaded test plugins.Full suite passes.
Notes