perf: cache Terraform provider plugins in terraform-check - #93
Conversation
The Makefile inits the root module and every example directory separately, so each one currently downloads the same providers again from scratch. Setting a shared TF_PLUGIN_CACHE_DIR collapses that to one download per run, and caching the directory across runs removes it almost entirely. Applied to both jobs that run terraform init (lint and tests). The directory is created explicitly because Terraform silently ignores the plugin cache when the directory does not already exist. Co-authored-by: Cursor <cursoragent@cursor.com>
Verified end to endNothing in this repo invokes Results from that run:
The cache is genuinely populated rather than saving an empty directory — the resulting entry is 46 MiB: And within the run, later inits stopped re-downloading: Timing corroborates it: the first azurerm install took ~10s, the second ~1.7s. That run started with a cold cache ( One note for reviewers reproducing locallyLocal results can mislead. If you have Generated with Cursor Agent (Opus 5) |
rakesh-gorige-nttd
left a comment
There was a problem hiding this comment.
Review — approved
Verified the diff adds plugin cache setup to both jobs that run terraform init (lint + tests). Good details: explicit mkdir -p (Terraform silently no-ops without it), $GITHUB_ENV instead of hardcoded paths, same pinned actions/cache as existing asdf cache, sensible key on **/versions.tf with prefix fallback.
End-to-end validation against a real module repo is convincing — cache populated (46 MiB), subsequent inits reuse providers. Standalone perf win; also sets up skeleton #38's floor check cheaply.
LGTM.
Review — approvedSummaryThis PR adds a shared The approach is sound and well-validated. LGTM. Good things
Non-blocking suggestions
Blocking issuesNone. |
Summary
Adds a shared Terraform provider plugin cache to both jobs in
reusable-terraform-check.ymlthat runterraform init(lintandtests).Why
tfmodule/initin the module Makefile initializes the root module and every example directory separately. Without a shared plugin cache each of those directories downloads the same providers from scratch, so a module with a root plus two examples pulls azurerm or aws three times per run — repeated across every PR in ~90 skeleton-managed repos.Setting
TF_PLUGIN_CACHE_DIRcollapses that to one download per run, and caching the directory across runs removes it almost entirely.Notes
mkdirthis change would be a no-op that looks correct.TF_PLUGIN_CACHE_DIRis exported via$GITHUB_ENVrather than a job-levelenv:so the path can be derived from$HOMEinstead of hardcoding/home/runner.actions/cachecommit already used by this workflow for the asdf tool cache, so there is no new action version to review.**/versions.tfwith arestore-keysprefix fallback, so a provider constraint change gets a fresh entry while still warm-starting from the previous one.Independent value
This stands on its own as a speedup for what CI already does. It also happens to be the prerequisite that makes an upcoming
required_versionfloor check cheap — that check inits a second time with an older Terraform, and provider binaries are independent of Terraform core version, so it reuses these same cached providers rather than re-downloading. Seelaunch-terraform-skeleton#38.Generated with Cursor Agent (Opus 5)
Made with Cursor