Repository navigation
Fix | Propagate the tofu/terraform exit code to the CLI - #336
Conversation
Every `leverage tofu|terraform` command discarded the exit code returned by `TFRunner.run`, so the CLI always exited 0, even when the binary failed. With `--layers` it also kept running the remaining layers after a failing one. Restore the behavior from before #316: raise `Exit(exit_code)` on a non-zero code for init, plan, apply, output, destroy, version, format, force-unlock, validate and import, which also stops `--layers` at the first failing layer. Closes #335 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. WalkthroughTerraform and OpenTofu commands now propagate nonzero binary exit codes through the CLI. Multi-layer execution stops after a failing layer. Tests cover exit codes and layer execution. ChangesTerraform and OpenTofu exit codes
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Possibly related issues
Suggested reviewers: Merge Risk:
|
Coverage Report for CI Build 43355745844Coverage increased (+1.7%) to 67.689%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions26 previously-covered lines in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
What
leverage tofu|terraformcommands now exit with the same code as the underlying binary, as they did before #316.Closes #335.
Why
leverage/modules/tf.pydiscarded the exit code returned byTFRunner.run(which does not raise), so the CLI always exited0:leverage tofu applypassed when the apply failed.plan -detailed-exitcodecould not report changes (2).--layerskept going after a failing layer.Regression from #316, shipped in v3.1.0. It also blocks #330 (the ref-arch test must fail when a
leverage tofucommand fails).Changes
leverage/modules/tf.py:if exit_code := tf.run(...): raise Exit(exit_code)ininit,plan,apply,output,destroy,version,format,force-unlock,validateandimport(same pattern astfautomv.py). SinceExitpropagates out ofinvoke_for_all_commands,--layersstops at the first failing layer.tests/conftest.py:leverage_runneraccepts an optionalworking_directory(its docstring already documented it), to run from a layers-group with--layers.tests/test_modules/test_tf.py: CLI tests assertingresult.exit_code:tofu/terraform× binary exit code0/1/2;--layersstops at the first failing layer, and runs all of them when none fails.Testing
--layersstop case).Out of scope
validate-layoutreturnsFalseon an invalid layout but still exits0. That was already the case before #316, so it is left for a separate change.🤖 Generated with Claude Code
Summary by CodeRabbit