Skip to content

Conversation

@lorengordon
Copy link
Contributor

@lorengordon lorengordon commented Dec 29, 2025

In old versions of terraform, the ternary operator did not short-circuit, and so the was_missing logic was needed as a hack to workaround both logic paths executing on every run. The module needed the hack to avoid failing when the package existed previously vs when it did not and was being created by the module itself.

In recent-ish versions of terraform, including the module min version 1.5.7, the ternary operator will shortcircuit, so it will only execute the true OR false logic, rather than both. This makes the was_missing logic unnecessary.

Further, in most recent versions of terraform, at least since 1.13.0, the was_missing logic resulted in a failure when separately building the package and then attempting to use the package in the same workflow. The failure occurred because terraform became more strict at enforcing that the return values of the fileexists() function be consistent between plan and apply phases.

Fixes #698

Breaking Changes

None

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

@lorengordon lorengordon changed the title fix: Avoids short-circuit issue where fileexists returns inconsistent results fix: Avoids issue due to strict requirement for fileexists to return consistent results Dec 30, 2025
In old versions of terraform, the ternary operator did not short-circuit,
and so the `was_missing` logic was a hack to workaround both paths executing
on every execution. The module needed the hack to avoid failing When the
package existed previously vs when it did not and was being created by the
module itself.

In recent-ish version of terraform, including the module min version 1.5.7,
the ternary operator will shortcircuit, so it will only execute the true OR
false logic, rather than both. This makes the `was_missing` logic unnecessary.

Further, in most recent versions of terraform, at least since 1.13.0, the
`was_missing` logic resulted in a failure when separately building the package
and then attempting to use the package in the same workflow. The failure occurred
because terraform became more strict at enforcing that the return values of the
`fileexists()` function be consistent between plan and apply phases.

Fixes terraform-aws-modules#698
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Building function package separately fails with Terraform v1.13

1 participant