`find --filter` reports a brand-new nested stack, but `stack run` with the same filter can't run anything against it
Describe the bug
We use terragrunt find --filter '[gitrange] | path/**' in CI to detect which stacks were affected by a PR, then run terragrunt stack run plan/apply scoped to that same filter.
For a brand-new nested stack (a stack block whose target has never been generated before), find reports it as an affected stack, but running plan with that exact same filter finds nothing and silently does nothing:
WARN No units discovered. Creating an empty runner.No error, no output, no nonzero exit code. From CI's perspective, the plan looks like it ran and found no changes, when in reality it never ran at all.
This also used to work on Terragrunt v1.0.4. On that version, find correctly reported nothing for the same brand-new stack, so our fallback logic knew to run unfiltered instead. On v1.1.6, find reports something, so we trust the filter, and the filter turns out to be a dead end.
Steps To Reproduce
mkdir tg-repro && cd tg-repro
git init -q
mkdir -p catalog/units/app catalog/stacks/child live-env
cat > catalog/units/app/terragrunt.hcl <<'EOF'
inputs = {
message = "hello"
}
EOF
cat > catalog/stacks/child/terragrunt.stack.hcl <<'EOF'
unit "app" {
source = "${get_repo_root()}/catalog/units/app"
path = "app"
}
EOF
git add -A
git commit -q -m "base: catalog only, no live-env stack yet"
BASE=$(git rev-parse HEAD)Add a brand-new top-level stack referencing the nested child stack. Nothing under live-env/ has been generated yet:
cat > live-env/terragrunt.stack.hcl <<'EOF'
stack "child" {
source = "${get_repo_root()}/catalog/stacks/child"
path = "child"
}
EOF
git add -A
git commit -q -m "add: live-env top-level stack referencing nested child stack"
NEW=$(git rev-parse HEAD)
FILTER="[${BASE}...${NEW}] | ./live-env/**"Run find with the same filter on v1.0.4 and v1.1.6:
/path/to/terragrunt-v1.0.4 find --filter "$FILTER" --format json
# []
/path/to/terragrunt-v1.1.6 find --filter "$FILTER" --format json
# [
# {
# "type": "stack",
# "path": "live-env/.terragrunt-stack/child"
# }
# ]Now use that exact same filter with stack run plan on v1.1.6:
terragrunt stack run plan --filter "$FILTER" --log-level warnWARN No units discovered. Creating an empty runner.find said there was something to look at. plan with the same filter finds nothing at all.
Expected behavior
If find --filter reports a stack as affected, running a command against that same filter should be able to act on it, either by generating and planning what's inside it, or by not reporting it as found in the first place. Reporting something as found that then can't actually be run against is the core problem here.
Must haves
- Steps for reproduction provided.
Nice to haves
- Terminal output
Versions
- Terragrunt version: v1.0.4 (last known-good) vs v1.1.6 (current)
- OpenTofu/Terraform version: v1.12.6 on darwin_arm64
- Environment details: macOS, darwin/arm64
Additional context
We've worked around this on our side by not trusting a positive find result alone before deciding whether to use a scoped filter, but wanted to report the underlying issue since it's surprising for find to report something that isn't actually actionable.
Source: gruntwork-io/terragrunt