feat: Re-download terraform binary if it appears to be invalid.#6454
Open
lukemassa wants to merge 6 commits into
Open
feat: Re-download terraform binary if it appears to be invalid.#6454lukemassa wants to merge 6 commits into
lukemassa wants to merge 6 commits into
Conversation
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a post-install validation step for Terraform/OpenTofu binaries by executing <binary> version after locating/downloading a requested version, aiming to surface invalid/wrong-arch binaries earlier (per #5670).
Changes:
- Refactors binary resolution into a new helper (
findOrDownloadVersionBinaryPath). - Updates
ensureVersionto execute the resolved binary withversionand fail early if it can’t run. - Disables Terraform checkpoint checks during this validation via
CHECKPOINT_DISABLE=1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
what
Run
terraform -versionafter installing/checking for the install of terraform.why
If the terraform binary is invalid an any way, for example it was built for the wrong arch, we now immediately detect that, and attempt to delete the file and retrigger the download, in the hopes the new version will work. If the second version also fails, we simply fail (which is also an improvement over the previous code, because before an error about architecture would be buried and confusing, see #5670)
I believe that running
terraform versionortofu versionshould be very fast and safe. However if it turns out this has any risk of false positives or performance issues, it's probably not worth doing.tests
I built an incompatible binary of terraform locally, and put it where the cache would pick it up, then it correctly deleted the old version and downloaded a new one.
references
Closes: #5670