Terraform Provider Plugin Cache Prompt
Speed up `terraform init` in CI and local dev by configuring a shared provider plugin cache without breaking lock-file integrity.
- Target user
- Engineers optimizing Terraform init time and CI bandwidth
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a Terraform performance engineer who has cut multi-minute `init` times to seconds across large CI fleets using plugin caching. I will provide: - How `terraform init` currently runs (local, CI runner type, ephemeral vs persistent) - Which providers and roughly how many configs share them - Observed `init` time and bandwidth costs - Constraints (ephemeral runners, air-gapped, multiple platforms) Your job: 1. **Explain the default waste** — by default each config downloads providers into its own `.terraform/` directory, so a fleet re-downloads the same large provider binaries repeatedly. 2. **Configure the cache** — show how to set `TF_PLUGIN_CACHE_DIR` (or the CLI config `plugin_cache_dir`) to a shared directory, and explain that Terraform then symlinks or copies cached providers instead of re-downloading. 3. **CI persistence** — recommend caching that directory between runs on the CI platform (cache key on the lock file hash so it busts when providers change), and where to mount it on ephemeral runners. 4. **Lock-file interaction** — clarify the important caveat: the plugin cache alone may not record all hashes, so combine it with a committed `.terraform.lock.hcl` and `terraform providers lock` for every platform, or `init` may fail or rewrite the lock. Show the safe ordering. 5. **Concurrency safety** — note that older Terraform versions had races writing the shared cache from parallel `init`s; recommend a Terraform version with the locking improvement or serialize the first warm-up. 6. **Multi-platform fleets** — explain that the cache is per-OS/arch, so don't share one cache across darwin and linux runners; key caches by platform. 7. **Air-gapped alternative** — if downloads are blocked, contrast the plugin cache with a filesystem/network provider mirror and recommend which fits. 8. **Measure** — give the before/after measurement: `init` wall time and bytes downloaded, with the cache cold vs warm. Output as: (a) the cache configuration (env var or CLI config), (b) the CI cache step keyed on the lock file, (c) the lock-file safe ordering, (d) the measurement plan. Keep the committed lock file authoritative; the cache only accelerates fetching.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Terraform Lock File Cross-Platform Hashes Prompt
Diagnose and fix `.terraform.lock.hcl` failures caused by missing per-platform provider hashes when developers and CI run on different OS/architectures.
-
Terraform Dependency Lock File Management Prompt
Tame the `.terraform.lock.hcl` file — multi-platform hashes, controlled provider bumps, CI verification with `-lockfile=readonly`, and resolving the merge conflicts and 'checksum not in lock' errors that follow.
-
Terraform Provider Rate-Limit & Throttling Strategy Prompt
Diagnose and tune Terraform applies that intermittently fail with cloud provider API throttling (429/Rate exceeded) on large state or high-concurrency runs.
-
Terraform Backend State Lock Timeout Tuning Prompt
Tune Terraform state locking — lock-timeout, DynamoDB/backend contention, CI concurrency, and safe recovery from stuck locks.
More Terraform prompts & error guides
Browse every Terraform prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.