Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Add deployment-level option to disable Terraform module caching #22834

Description

@blinkagent

Summary

Add a deployment-level (global) option to disable Terraform module caching across all templates, instead of requiring administrators to toggle each template individually.

The per-template disable_module_cache toggle already exists in v2.31+ (verified in code), but there is no server-wide flag and no deployment default that templates can inherit from. Admins with many templates (e.g. ~100) currently have to update each one by hand.

Verified current state (as of main, 2026-06-08)

  • Per-template toggle exists in v2.31+. disable_module_cache is a real field:
    • codersdk/templates.go exposes DisableModuleCache bool on the template and DisableModuleCache *bool on the update-meta request.
    • DB migration 000416_workspace_module_reuse_toggle adds disable_module_cache BOOL NOT NULL DEFAULT false to the templates table.
    • Wired through coderd/templates.go, coderd/templates_meta_update.go, coderd/provisionerdserver/provisionerdserver.go, the audit table, generated TS types, and the Template Settings UI.
  • Release coverage: present in release/2.31, release/2.32, release/2.32.0-rc, and main; absent in release/2.30.
  • No deployment-level / global option exists. No matching flag or env var (e.g. CODER_DISABLE_TERRAFORM_MODULE_CACHE) was found in codersdk/deployment.go, cli/, enterprise/cli/, or cli/server.go.
  • No Terraform provider support. The coderd Terraform provider (coderd_template resource) does not expose a disable_module_cache attribute, so templates managed as code cannot set it.

Proposed Behavior

  1. Deployment-level configuration option — A global flag (e.g. CODER_DISABLE_TERRAFORM_MODULE_CACHE) to disable module caching across all templates.
  2. Per-template override — The existing per-template disable_module_cache setting should be able to override the deployment default, so individual templates can opt back in/out.
  3. UI messaging when globally disabled — When caching is disabled at the deployment level, the template settings UI should indicate this clearly, e.g.: "Terraform module caching is disabled at the deployment level. Modules will be re-downloaded on each workspace build. Note: disabling caching means provisioner nodes may accumulate Terraform module files on disk, which can impact stability at scale."
  4. Terraform provider support — Expose disable_module_cache on the coderd_template resource in the coderd Terraform provider, so templates managed as code can set the toggle. (Lives in the separate provider repo; tracked as part of this body of work.)

Background: why caching exists (do not regress these)

Module caching was introduced (#21398, v2.30) to solve real problems, and the global opt-out must remain opt-in so these defaults are preserved:

  • Disk/memory pressure: Repeated module downloads on every workspace build could cause an ever-growing .terraform/modules cache on provisioner nodes, leading to OOM at scale.
  • Stability: Upstream module changes could break workspace restarts without any template changes.
  • Performance: Eliminating repeated downloads speeds up workspace startup.

Out of scope / tracked elsewhere

  • Backporting the per-template toggle to release/2.30.

original description

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Since v2.30 (#21398), Terraform modules are cached at template import time and reused for all subsequent workspace builds. This means that semver version constraints like ~> 1.1.0 are resolved once at import time and then effectively pinned — the constraint is never re-evaluated on workspace builds, even when newer matching versions are available upstream.

This silently overrides Terraform's native version resolution semantics. If a user specifies version = "~> 1.1.0", the intent is "give me the latest patch within this range." The caching behavior changes this to "pin whatever version was latest at import time," which is fundamentally different from what the user declared in their configuration.

Additional context: disable_module_cache toggle not available in v2.30.x

A per-template toggle (disable_module_cache) was added in #21931, which merged to main on Feb 5, 2026. However, this was never cherry-picked to the release/2.30 branch. This means:

Additionally, even in v2.31+ where the per-template toggle exists:

  • There is no deployment-level or server-wide flag to disable module caching — administrators with many templates (e.g. ~100) must update each template individually
  • The coder/coderd Terraform provider (coderd_template resource) does not expose the disable_module_cache attribute, so templates managed via Terraform cannot use this setting

Background: why caching was introduced

The caching behavior was introduced to solve real problems:

  • Disk/memory pressure: Repeated module downloads on every workspace build could cause ever-growing .terraform/modules cache on provisioner nodes, leading to OOM or exit code 1 on coderd instances at scale
  • Stability: Upstream module changes could break workspace restarts without any template changes
  • Performance: Eliminating repeated downloads speeds up workspace startup

These are valid concerns. However, the current implementation is all-or-nothing with no way to manage it at the deployment level, and it overrides Terraform's native version resolution without the user's consent.

Expected Behavior

  1. Terraform semver constraints should be respected as written — if a user specifies ~> 1.1.0, they expect the latest matching version to be fetched on each workspace build, not a cached/pinned version from import time. If explicit pinning is desired, the user would specify an exact version (e.g. version = "1.1.3").
  2. Deployment-level configuration option — A global flag (e.g. CODER_DISABLE_TERRAFORM_MODULE_CACHE) to disable module caching across all templates, rather than requiring per-template updates. Per-template settings could still override the deployment default.
  3. UI messaging when globally disabled — When caching is disabled at the deployment level, the template settings UI should indicate this clearly, e.g.: "Terraform module caching is disabled at the deployment level. Modules will be re-downloaded on each workspace build. Note: disabling caching means provisioner nodes may accumulate Terraform module files on disk, which can impact stability at scale."
  4. Backport — The disable_module_cache toggle should be backported to v2.30.x so that users on that release line have a way to opt out.
  5. Terraform provider support — The coder/coderd Terraform provider should expose the disable_module_cache attribute on the coderd_template resource.

Steps to Reproduce

  1. Create a template that references a module with a semver constraint:

    module "base_template" {
      version = "~> 1.1.0"
      # ...
    }
  2. Push the template version (module resolves to e.g. 1.1.3)

  3. A new version 1.1.4 is released upstream

  4. Start a workspace — it still uses 1.1.3 from cache, ignoring the available 1.1.4

Environment

  • Coder version: v2.30.3+55da992 (confirmed: disable_module_cache toggle is absent)

Created on behalf of @maxbeutel

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions