Skip to content

fix: add tool-cache-dir so terraform and terragrunt binaries are reused between runs - #2772

Open
s1ntaxe770r wants to merge 1 commit into
developfrom
fix/terragrunt-tool-cache
Open

s1ntaxe770r wants to merge 1 commit into
developfrom
fix/terragrunt-tool-cache

Conversation

@s1ntaxe770r

Copy link
Copy Markdown
Collaborator

The action downloaded terraform (via hashicorp/setup-terraform) and terragrunt into a per-job temp directory on every run, with a single curl and no retry. There was no way to point the action at a directory where these binaries could be kept between runs, so on self-hosted runners every job re-downloaded them, and one transient network error from github.com or releases.hashicorp.com failed the whole job.

This PR adds a tool-cache-dir input. Both setup steps now store the binary at <tool-cache-dir>/<tool>/<version>/<arch>/, reuse it when a working binary is already there, and retry the download when it is not. The default is the runner's own tool cache ($RUNNER_TOOL_CACHE), so GitHub-hosted runners behave as before; on self-hosted runners you point it at a persistent volume, the same way terraform-cache-dir already works for providers.

      - uses: diggerhq/digger@vLatest
        with:
            setup-terraform: true
            terraform-version: 1.5.5
            setup-terragrunt: true
            terragrunt-version: 1.1.2
            terraform-cache-dir: /home/myuser/mnt/terraform-cache
            tool-cache-dir: /home/myuser/mnt/terraform-cache/tools

Notes:

  • hashicorp/setup-terraform is replaced with a bash step (we already ran it with terraform_wrapper: false). It resolves latest, downloads the zip, and writes the TFE credentials block to the CLI config file as before. terraform-version now accepts an exact version or latest; semver ranges such as ~1.5 are no longer accepted.
  • A binary that fails to run (for example a truncated download) is re-downloaded and replaced atomically.
  • Old versions are not pruned; delete <tool-cache-dir>/<tool>/<version> by hand.

Docs:

Testing

End to end on https://github.com/s1ntaxe770r/terragrun-test with the action used three times in one job against the same tool-cache-dir: https://github.com/s1ntaxe770r/terragrun-test/actions/runs/44488381461

run terraform 1.5.5 terragrunt 1.1.2
1, empty cache downloaded downloaded
2, same cache dir Using cached Terraform 1.5.5 from .../terraform/1.5.5/amd64/terraform, cache dir unchanged Using cached Terragrunt v1.1.2 from .../terragrunt/1.1.2/amd64/terragrunt, cache dir unchanged
3, both binaries truncated first re-downloaded, size restored re-downloaded, size restored

Also ran each step's script locally for the latest, rejected-range and TFE credentials cases.

🧠 Ai UsageDetails (if applicable):

Fix, docs and e2e workflow drafted with Claude Code; reviewed manually and verified in the test repo linked above.

…retry downloads

Setup Terragrunt downloaded into RUNNER_TEMP on every run with a single
curl, so a connection reset from github.com failed the whole job, and
hashicorp/setup-terraform did the same against releases.hashicorp.com.
Both are now bash steps that store the binary under tool-cache-dir
(default RUNNER_TOOL_CACHE) as <tool>/<version>/<arch>, skip the download
when a working binary is already there, and retry the curl.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
opentaco-docs c71593a Commit Preview URL

Branch Preview URL
Nov 19 2026, 08:40 AM

This branch has not been deployed

No deployments
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.

1 participant