{
  "slug": "terraform-module-sources-and-versions-support-variables-and-locals-89758da570a3",
  "title": "Terraform module sources and versions support variables and locals",
  "tools": [
    "terraform"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-04-29T14:05:34.000Z",
  "announced_at": "2026-04-29T14:05:34.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "When selecting a module source or registry version from configuration values, use input variables marked `const = true`; you can reference them directly or through locals. Provide their values with a supported variable mechanism, then run `terraform init` after changing the module source or version.",
    "examples": [
      "variable \"module_source\" {\n  type  = string\n  const = true\n}\n\nmodule \"example\" {\n  source = var.module_source\n}\n\nterraform plan -var='module_source=./<module-directory>'",
      "variable \"module_repo\" {\n  type  = string\n  const = true\n}\n\nvariable \"module_ref\" {\n  type  = string\n  const = true\n}\n\nlocals {\n  module_source = \"git::https://example.com/${var.module_repo}.git?ref=${var.module_ref}\"\n}\n\nmodule \"example\" {\n  source = local.module_source\n}\n\nterraform plan -var='module_repo=<repository>' -var='module_ref=<branch-or-tag>'",
      "variable \"module_version\" {\n  type  = string\n  const = true\n}\n\nmodule \"example\" {\n  source  = \"<registry-namespace>/<module>/<provider>\"\n  version = var.module_version\n}\n\nterraform plan -var='module_version=<version-constraint>'"
    ],
    "gotchas": [
      "Version: 1.15.0",
      "const: Set to `true` for any input variable referenced by a module `source` or `version`; its value must be known during configuration loading.",
      "source (required): Module source expression; it can reference constant input variables and local values.",
      "version: Registry module version constraint; it can reference constant input variables and local values. Use only with a registry source.",
      "-var 'NAME=VALUE': Set one root input variable value; the option can be repeated.",
      "-var-file=FILENAME: Set root input variable values from a `.tfvars` file; the option can be repeated.",
      "TF_VAR_name: Environment variable form for setting an input variable; replace `name` with the variable name.",
      "Prerequisite: Terraform v1.15.0 introduced `const` variables for module source/version expressions.",
      "Prerequisite: Run `terraform init` after modifying a module `source` or `version`.",
      "Nested modules can use variables in module sources only when their input variables are declared `const = true`.",
      "The release text states that variables and locals are supported in module source and version attributes, but the linked description examples only show `source`."
    ]
  },
  "why_it_matters": "Select a module source or version using a configuration value.",
  "sources": [
    "https://github.com/hashicorp/terraform/releases/tag/v1.15.0",
    "https://github.com/hashicorp/terraform/pull/38217",
    "https://developer.hashicorp.com/terraform/language/modules/configuration",
    "https://developer.hashicorp.com/terraform/cli/commands/plan",
    "https://developer.hashicorp.com/terraform/cli/config/environment-variables",
    "https://developer.hashicorp.com/terraform/language/block/module?product_intent=terraform"
  ],
  "rank": 0.96039,
  "judge": {
    "publish": true,
    "judge_model": "codex-cli/gpt-6-luna+typesafe/jev-1.13.0",
    "prompt_version": "extract-v7+enrich-v2+judge-v2x3+jev-publish-v1"
  },
  "review_state": "approved",
  "provenance": {
    "run_id": "wave1b-20261016",
    "verdict_id": "wave1b-20261016:wave1b-20261016-d17819c10e9fea85-5:gate",
    "evidence_hash": "16bec6ef2c7e0d436c7f5efd8b0757c97f98898e49a1f97c8a61276d3aa64597"
  },
  "review": {
    "draft_hash": "4344a0ee32a057f63f41886bedf6e4081d8ac52acc6f4859f90bca5dd4e65d1d",
    "reviewer": "publication-gate",
    "reviewed_at": "2026-10-07T00:00:00.000Z",
    "decision": "wave1b-20261016:gate",
    "reason": "3 of 3 judge runs approved with p_yes >= 0.9 (mean 0.96 >= 0.9; 2 needed) and Jev gave 0.71 (>= 0.6 needed)."
  }
}
