How do I cache providers on private workers?

Last updated: November 25, 2026

Private workers can reuse downloaded providers instead of downloading them on every run. To do that, put a provider cache on shared storage.

What's cached automatically
  • Tool binaries (terraform, tofu, kubectl) are cached on each Docker-based worker host.

  • Terragrunt with OpenTofu: from Terragrunt 0.89.0 and OpenTofu 1.10.0, providers are cached automatically.

Providers for Terraform and OpenTofu stacks aren't cached unless you set up a provider cache.

Set up a provider cache

Use storage that every worker can read and write at the same time, such as Amazon FSx for OpenZFS, or an NFS server backed by EBS. Don't share a multi-attached EBS volume directly: ext4 and XFS aren't cluster-aware, and concurrent access can corrupt them.

Docker-based workers: mount the shared directory on every worker, bind-mount it into runs, and point TF_PLUGIN_CACHE_DIR at it:

export SPACELIFT_WORKER_EXTRA_MOUNTS="/mnt/spacelift-provider-cache:/mnt/provider-cache"

Then set TF_PLUGIN_CACHE_DIR=/mnt/provider-cache on the stacks that should use the cache.

Kubernetes workers: add a ReadWriteMany volume to the run pod, and set TF_PLUGIN_CACHE_DIR on the worker container:

spec:
  pod:
    volumes:
      - name: provider-cache
        persistentVolumeClaim:
          claimName: provider-cache
    workerContainer:
      volumeMounts:
        - name: provider-cache
          mountPath: /opt/spacelift/provider-cache
      env:
        - name: TF_PLUGIN_CACHE_DIR
          value: /opt/spacelift/provider-cache

Commit your .terraform.lock.hcl files: Terraform 1.4+ and OpenTofu only use a cached provider when the lock file has a matching hash. With Terraform, warm the cache with a single run before using it with a busy pool.

"Error: Required plugins are not installed"

With a provider cache, .terraform/providers links to the cache, outside the workspace. If a run stops for confirmation or approval, the workspace is restored before apply without those links, so the providers are missing.

To fix it, recreate the links in a before_apply hook.

Terraform and OpenTofu stacks:

: "${TF_PLUGIN_CACHE_DIR:?not set - refusing to symlink}" && rm -rf .terraform/providers && mkdir -p .terraform "$TF_PLUGIN_CACHE_DIR" && ln -s "$TF_PLUGIN_CACHE_DIR" .terraform/providers

Terragrunt stacks, which keep a .terraform folder for each unit:

: "${TF_PLUGIN_CACHE_DIR:?not set - refusing to symlink}" && mkdir -p "$TF_PLUGIN_CACHE_DIR" && find . -type d -name .terraform -prune -exec sh -c 'for d; do echo "Relinking $d/providers -> $TF_PLUGIN_CACHE_DIR"; rm -rf "$d/providers" && ln -s "$TF_PLUGIN_CACHE_DIR" "$d/providers" || exit 1; done' sh {} +

Alternatively, run terraform init (or tofu init) as a before_apply hook. Don't use init -upgrade: it can install different provider versions from the ones used for the plan.

Sources