# Step 16 — Implementation Detail 1. `TF_PLUGIN_CACHE_DIR` defaults to `.cache/terraform-plugins` under the repository root (already gitignored and kept out of the image build context). Set it empty to disable. `Settings.terraform_plugin_cache()` resolves it to an absolute path, since checks run in scratch directories. 2. `TerraformRunner` creates the directory on first use and passes it to Terraform. 3. It also sets `TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE=true`. A scratch directory has no dependency lock file, and without this Terraform downloads a cached provider again to verify it, which defeats the cache. 4. `terraform init` calls are serialised by a lock when the cache is in use, because Terraform's plugin cache is not safe for concurrent installs. Measured on 2026-10-07 with a one-resource configuration on the Google provider (`~> 6.0`), on this machine: | | Seconds per `terraform validate` | |---|---| | No cache | 7.3 to 7.8 | | Cache, first use (downloads once) | 7.3 | | Cache, later uses | 1.6 to 2.0 | So each check after the first saves about 5.5 seconds. The stopped run of 2026-10-06 made 7 validate calls in 16 minutes and more through its Revisions; at 12 to 15 calls a case, with the scoring's own check, that is roughly 1 to 1.5 minutes a case. The saving is real but small against a 35 minute run; it grows on a slower network. Costs: the cache holds each provider version once (117 MB for one Google provider version; the existing folder holds 600 MB across versions). In the container it is created under `/app/.cache` at run time and is lost with the container; pre-loading it into the image, or mounting a volume, would carry the saving across restarts and is not done. Tests: `tests/tools/test_local.py`, "the provider cache", using a stand-in terraform binary.