Skip to content

fix: Avoids issue due to strict requirement for fileexists to return consistent results#722

Merged
antonbabenko merged 1 commit intoterraform-aws-modules:masterfrom
lorengordon:fix/build-pkg-only
Jan 25, 2026
Merged

fix: Avoids issue due to strict requirement for fileexists to return consistent results#722
antonbabenko merged 1 commit intoterraform-aws-modules:masterfrom
lorengordon:fix/build-pkg-only

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
@lorengordon
Copy link
Contributor Author

@antonbabenko Any chance you might have a bit to review this one? I think I tracked down the rationale for the original implementation, which is no longer needed in the terraform min version supported by the module, so this patch is just removing that was_missing logic...

@lorengordon
Copy link
Contributor Author

I don't see a CODEOWNERS file... are there any other maintainers that can review/merge?

@antonbabenko
Copy link
Member

@lorengordon I will review this one and another related one during the weekend. I know I am rather slow with these reviews sometimes.

@antonbabenko antonbabenko merged commit d6b4321 into terraform-aws-modules:master Jan 25, 2026
31 checks passed
antonbabenko pushed a commit that referenced this pull request Jan 25, 2026
## [8.2.1](v8.2.0...v8.2.1) (2026-01-25)

### Bug Fixes

* Avoids issue due to strict requirement for fileexists to return consistent results ([#722](#722)) ([d6b4321](d6b4321))
@antonbabenko
Copy link
Member

This PR is included in version 8.2.1 🎉

@antonbabenko
Copy link
Member

Thank you very much for the detailed research and the fix @lorengordon !

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

2 participants