Skip to content

BUG | leverage tofu/terraform always exits 0, even when the binary fails #335

Closed

Description

@diego-ojeda-binbash

Problem

Every leverage tofu / leverage terraform command exits with 0, even when the underlying binary fails.

leverage/modules/tf.py calls tf.run(...) and discards the exit code it returns in _init, _plan, _apply, _output, _destroy, version, format, force-unlock, validate and import. Runner.run returns the code (it does not raise), so nothing propagates it to the process.

Reproduction

With a fake tofu on PATH that exits 1 (or 2), from a layer:

$ leverage tofu plan; echo $?
0
$ leverage tofu plan -detailed-exitcode; echo $?   # tofu returned 2
0
$ leverage tofu apply -auto-approve; echo $?       # tofu returned 1
0

Same result for init, destroy, output, and with --layers (every layer runs even after one fails).

Impact

Origin

Regression introduced in #316 (Docker removal), released in v3.1.0. Before it, every command did exit_code = tf.start_in_layer(...); if exit_code: raise Exit(exit_code). It also contradicts the spec: "if the underlying binary fails, the CLI exits with the same exit code".

aws, kubectl and tfautomv are not affected (they already propagate the code).

Proposed fix

  • Restore raise Exit(exit_code) on a non-zero exit code for all the commands above.
  • With --layers, stop at the first failing layer (behavior before Feat | Remove docker dependency #316).
  • Add CLI tests asserting result.exit_code for each command, including --layers and -detailed-exitcode (2).

Activity

  1. added
    bug
    on Nov 13, 2026
  2. diego-ojeda-binbash commented on Nov 13, 2026

    @diego-ojeda-binbash
    ContributorAuthor

    Prior occurrence: #272 (init did not exit with an error when it failed internally), fixed in 2024. #316 reintroduced it, this time for every tofu/terraform command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions