Skip to content

Pin TF_PLUGIN_CACHE_DIR to a predictable path on terraformer (#274)#275

Merged
akuzminsky merged 1 commit into
mainfrom
pin-tf-plugin-cache-dir-274
Jun 24, 2026
Merged

Pin TF_PLUGIN_CACHE_DIR to a predictable path on terraformer (#274)#275
akuzminsky merged 1 commit into
mainfrom
pin-tf-plugin-cache-dir-274

Conversation

@akuzminsky

Copy link
Copy Markdown
Member

Closes #274.

Why

The terraformer host runs terraform across many working directories. By default terraform init downloads provider binaries into each workdir's .terraform/providers/..., so the real Go binaries land at per-workdir paths that vary run to run.

We want AWS Inspector EC2 scanning enabled on this host (to catch real OS-package CVEs) while suppressing only the noise from Terraform provider binaries. Inspector suppression filters match file_path with EQUALS / PREFIX / NOT_EQUALS only — no glob, no CONTAINS — so the provider binaries must sit under a single, stable prefix to be targetable.

What

New profile::terraformer::plugin_cache, included from profile::terraformer:

  • Creates /var/cache/terraform/plugins (Terraform won't create the cache dir itself).
  • Exports TF_PLUGIN_CACHE_DIR via /etc/profile.d/terraform-plugin-cache.sh for login shells.
  • Makes the cache writable by the admin group — setgid + a default POSIX ACL (d:g:admin:rwx), since terraform is run by non-privileged users in the admin group and setgid alone loses group-write on nested provider dirs under the default umask. Installs the acl package; the setfacl exec is idempotent via a getfacl guard.

Mirrored across the top-level, development, and sandbox module copies (matching the prior terraformer change in #229).

Verified on a live terraformer

  • TF_PLUGIN_CACHE_DIR=/var/cache/terraform/plugins in a login shell.
  • /var/cache/terraform/plugins is drwxrwsr-x+ group admin; nested provider dirs inherit setgid + the ACL.
  • After terraform init, real provider binaries live once under /var/cache/terraform/plugins/registry.terraform.io/... and every .terraform/providers/... entry in the workdir is a symlink back into the cache.

Companion

Pairs with infrahouse/terraform-aws-terraformer#34 (make the Inspector EC2 exclusion opt-in, then suppress the provider-binary noise via this predictable path).

🤖 Generated with Claude Code

Configure a shared Terraform provider plugin cache at a fixed path so
provider binaries are stored once under a deterministic prefix instead of
per-workdir .terraform/providers paths that vary run to run. This gives AWS
Inspector EC2 scanning a single PREFIX anchor to suppress the provider-binary
noise while still scanning the host's OS packages.

New profile::terraformer::plugin_cache:
- creates /var/cache/terraform/plugins (terraform won't create it itself)
- exports TF_PLUGIN_CACHE_DIR via /etc/profile.d for login shells
- makes the cache writable by the admin group (setgid + default POSIX ACL)
  so non-privileged admin users sharing the box can populate it

Mirrored across the top-level, development, and sandbox module copies.

Pairs with infrahouse/terraform-aws-terraformer#34.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@akuzminsky akuzminsky merged commit a87454e into main Jun 24, 2026
2 checks passed
@akuzminsky akuzminsky deleted the pin-tf-plugin-cache-dir-274 branch June 24, 2026 23:39
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.

Pin TF_PLUGIN_CACHE_DIR to a predictable path on terraformer

2 participants