Skip to content

fix: check tool cache before downloading Terraform - #570

Open
igaskin wants to merge 1 commit into
hashicorp:mainfrom
igaskin:feat/toolcache
Open

igaskin wants to merge 1 commit into
hashicorp:mainfrom
igaskin:feat/toolcache

Conversation

@igaskin

@igaskin igaskin commented Aug 5, 2026 •

Copy link
Copy Markdown

Without a tc.find() guard the action re-downloads Terraform on every run. Add tc.find() check before downloading; cache with tc.cacheDir() after first download.

Fixes #510

tested locally
first run

trigger: setup-terraform {"terraform_version": "1.9.8"} (image=node:24, entry=dist/index.js)
::debug::Finding releases for Terraform version 1.9.8
::debug::Getting build for Terraform version 1.9.8: linux arm64
::debug::isExplicit: 1.9.8
::debug::explicit? true
::debug::checking cache: /opt/hostedtoolcache/terraform/1.9.8/arm64
::debug::not found
::debug::Downloading Terraform CLI from https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_linux_arm64.zip
::debug::Downloading https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_linux_arm64.zip
::debug::Destination /tmp/runner-temp/39193455-5fa1-42d3-9138-738beb4dad15
::debug::download complete
::debug::Extracting Terraform CLI zip file
[command]/usr/bin/unzip -o -q /tmp/runner-temp/39193455-5fa1-42d3-9138-738beb4dad15
::debug::Terraform CLI path is /tmp/runner-temp/fe73a3f6-3656-4a32-8d72-397a35642aad.
::debug::Caching tool terraform 1.9.8 arm64
::debug::source dir: /tmp/runner-temp/fe73a3f6-3656-4a32-8d72-397a35642aad
::debug::destination /opt/hostedtoolcache/terraform/1.9.8/arm64
::debug::finished caching tool
::debug::Moving /opt/hostedtoolcache/terraform/1.9.8/arm64/terraform to /opt/hostedtoolcache/terraform/1.9.8/arm64/terraform-bin.
::debug::Copying /actions/setup-terraform/dist/index1.js to /opt/hostedtoolcache/terraform/1.9.8/arm64/terraform.
::set-env name=TERRAFORM_CLI_PATH::/opt/hostedtoolcache/terraform/1.9.8/arm64
::add-path::/opt/hostedtoolcache/terraform/1.9.8/arm64

second run

trigger: setup-terraform {"terraform_version": "1.9.8"} (image=node:24, entry=dist/index.js)
::debug::Finding releases for Terraform version 1.9.8
::debug::Getting build for Terraform version 1.9.8: linux arm64
::debug::isExplicit: 1.9.8
::debug::explicit? true
::debug::checking cache: /opt/hostedtoolcache/terraform/1.9.8/arm64
::debug::Found tool in cache terraform 1.9.8 arm64
::debug::Moving /opt/hostedtoolcache/terraform/1.9.8/arm64/terraform to /opt/hostedtoolcache/terraform/1.9.8/arm64/terraform-bin.
::debug::Copying /actions/setup-terraform/dist/index1.js to /opt/hostedtoolcache/terraform/1.9.8/arm64/terraform.
::set-env name=TERRAFORM_CLI_PATH::/opt/hostedtoolcache/terraform/1.9.8/arm64
::add-path::/opt/hostedtoolcache/terraform/1.9.8/arm64

@hashicorp-cla-app

hashicorp-cla-app Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@igaskin
igaskin force-pushed the feat/toolcache branch 4 times, most recently from 9147cbf to 85ef7c7 Compare August 6, 2026 21:42
Without a tc.find() guard the action re-downloads Terraform on every
run, even when the requested version is already present in the runner's
tool cache. This also caused the wrapper-installation step to fail on
re-runs because it attempted to rename terraform→terraform-bin when
terraform-bin already existed.

Changes:
- Add tc.find() check in run(); skip download when version is cached
- Cache the extracted directory with tc.cacheDir() after first download
- Make installWrapper() idempotent: skip the rename when terraform-bin
  already exists (safe to call on a cache-hit path)

Fixes hashicorp#510

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@igaskin
igaskin marked this pull request as ready for review August 6, 2026 21:48
@igaskin
igaskin requested a review from a team as a code owner August 6, 2026 21:48
@igaskin

igaskin commented Aug 7, 2026

Copy link
Copy Markdown
Author

@austinvalle is this the kind of PR you would be willing to review?

@samtarplee

Copy link
Copy Markdown

Are there any plans to implement this? It would help enormously with some rate limiting issues I'm encountering on self-hosted runners when installing terraform

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.

Support caching of Terraform binary on self-hosted runners

2 participants