Skip to content

fix(docker): Downloader of opentofu to specific version was broken, only latest worked - #1001

Merged
MaxymVlasov merged 1 commit into
masterfrom
fix-opentofu-specific-version-regex
Jul 24, 2026
Merged

fix(docker): Downloader of opentofu to specific version was broken, only latest worked#1001
MaxymVlasov merged 1 commit into
masterfrom
fix-opentofu-specific-version-regex

Conversation

@MaxymVlasov

@MaxymVlasov MaxymVlasov commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator
  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • This PR enhances existing functionality.

Description of your changes

What

This section was generated by AI.

  • Fixed tools/install/opentofu.sh's GH_RELEASE_REGEX_SPECIFIC_VERSION regex, which never matched any real OpenTofu release asset. It expected the filename itself to start with a v glued to the version (v${VERSION}_${TARGETOS}...), but OpenTofu's actual asset filenames have no v prefix (e.g. tofu_1.12.5_linux_amd64.tar.gz) - the v only appears in the release tag's URL path segment (.../download/v1.12.5/tofu_1.12.5_linux_amd64.tar.gz), not the filename.
  • Net effect before this fix: pinning any specific OpenTofu version (via --build-arg OPENTOFU_VERSION=X.Y.Z at Docker build time, or the --tool-version=X.Y.Z hook-config from #) silently failed to download - only OPENTOFU_VERSION=latest ever worked, since GH_RELEASE_REGEX_LATEST doesn't reference the version at all.

Why

Accidentally found during work on a different PR.

How can we test changes

This section was generated by AI.

TARGETOS=linux TARGETARCH=amd64 VERSION=1.12.5
curl -s https://api.github.com/repos/opentofu/opentofu/releases | grep -o -E -i -m 1 "https://.+?_${VERSION}_${TARGETOS}_${TARGETARCH}.tar.gz"
# before this fix: no output (regex never matches)
# after this fix:  https://github.com/opentofu/opentofu/releases/download/v1.12.5/tofu_1.12.5_linux_amd64.tar.gz

Also verified with a full end-to-end download/extract of the resulting URL - the extracted binary correctly reports OpenTofu v1.12.5.

Assisted-by

Specific models used per commit are specified in the commit messages.

  • Assisted-by: Sisyphus:claude-sonnet-5 claude (da0828e)

GH_RELEASE_REGEX_SPECIFIC_VERSION expected the asset filename itself to
contain a 'v' prefix glued to the version (v${VERSION}_${TARGETOS}...),
but OpenTofu's release assets are named tofu_${VERSION}_${TARGETOS}...
with no 'v' - it only appears in the release tag's URL path segment.
The regex never matched, so `docker build --build-arg OPENTOFU_VERSION=X.Y.Z`
(pinning to anything other than 'latest') always failed to download.

Verified against the live GitHub API and a real end-to-end download.

Assisted-by: Sisyphus:claude-sonnet-5 claude
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The OpenTofu installer updates its version-specific GitHub release filename regex from a v${VERSION} prefix to an underscore-delimited _${VERSION} pattern. The latest-release matching and installation flow remain unchanged.

Changes

OpenTofu installer

Layer / File(s) Summary
Version-specific release matching
tools/install/opentofu.sh
Updates the release regex to match _${VERSION}_${TARGETOS}_${TARGETARCH}.tar.gz filenames.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Suggested reviewers: antonbabenko

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the bug fix: specific-version OpenTofu downloads were broken while latest worked.
Description check ✅ Passed The description is directly related to the change and accurately explains the regex fix and its effect.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-opentofu-specific-version-regex

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@MaxymVlasov MaxymVlasov changed the title fix(opentofu): match real asset filename when pinning a specific version fix(docker): opentofu downloader to specific version was broken, only latest worked Jul 23, 2026
@MaxymVlasov MaxymVlasov changed the title fix(docker): opentofu downloader to specific version was broken, only latest worked fix(docker): Opentofu downloader to specific version was broken, only latest worked Jul 23, 2026
@MaxymVlasov MaxymVlasov changed the title fix(docker): Opentofu downloader to specific version was broken, only latest worked fix(docker): Downloader of opentofu to specific version was broken, only latest worked Jul 23, 2026
@MaxymVlasov MaxymVlasov added area/docker bug Something isn't working labels Jul 23, 2026
@MaxymVlasov
MaxymVlasov marked this pull request as ready for review July 23, 2026 22:18
Copilot AI review requested due to automatic review settings July 23, 2026 22:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the OpenTofu installer’s GitHub release URL matching so pinned versions (e.g., OPENTOFU_VERSION=1.12.5) successfully resolve and download, instead of only latest working. This aligns the regex with OpenTofu’s real asset filename format (no v prefix in the filename).

Changes:

  • Corrected the GH_RELEASE_REGEX_SPECIFIC_VERSION pattern in tools/install/opentofu.sh to match actual OpenTofu release asset URLs for a specific version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MaxymVlasov
MaxymVlasov merged commit 6a72379 into master Jul 24, 2026
52 of 67 checks passed
@MaxymVlasov
MaxymVlasov deleted the fix-opentofu-specific-version-regex branch July 24, 2026 00:43
@antonbabenko

Copy link
Copy Markdown
Owner

This PR is included in version 1.108.1 🎉

MaxymVlasov added a commit that referenced this pull request Jul 24, 2026
hooks/_common.sh and tools/install/_common.sh both used
"${var^^}" for uppercasing (e.g. tflint -> TFLINT_VERSION), which
is bash 4+ only. macOS ships bash 3.2.57 by default (Apple's last
GPLv2 release) and this repo explicitly documents 'BASH 3.2.57 or
newer' as a supported baseline (README.md) - CI's macOS runner hit
exactly this with 'bad substitution' once the sdist-packaging fix
let it reach this code for the first time.

Replaced both with a portable 'tr' pipeline. Also fix
tools/install/opentofu.sh's GH_RELEASE_REGEX_SPECIFIC_VERSION: it
required a literal 'v' immediately before the version in the asset
*filename* (only the release *tag* has that 'v', e.g.
tofu_1.12.5_linux_amd64.tar.gz has no 'v'), so --tool-version pinning
for opentofu specifically always fell through to a blank curl URL.
(Same fix as already proposed standalone in PR #1001 against master;
duplicated here since this branch predates that PR and my test
suite's real-download coverage was tflint-only, so it never
exercised this path.)

Verified all three fixes against a real bash 3.2.57 (docker run
bash:3.2, matching macOS's exact version) end-to-end: real tflint
and real opentofu downloads both succeed and produce a working,
correctly-versioned cached binary.

Assisted-by: Sisyphus:claude-sonnet-5 claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docker bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants