A platform team wants one root module to choose a registry module's version from an input variable so each environment's pipeline can pass its own version. The configuration targets Terraform 1.15. Which approach is supported?
Select an answer to reveal the explanation.
Short Explanation
Terraform needs to know which module to download before it does anything else, so the variable has to be nailed down early. That's what const = true promises: a known, constant value you hand over at init time. A regular variable, or anything computed later, shows up too late for the download.
Full Explanation
Terraform 1.15 allows module source and version arguments to reference input variables and local values, but any input variable used there must declare const = true. A const variable can hold only a known, constant value that does not depend on results computed during a plan, which lets Terraform evaluate it while loading configuration, including during terraform init when modules are installed. Each pipeline therefore passes its chosen version as a variable value at init and supplies the same value to later commands such as plan, so the installed module and the evaluated configuration agree. Templating the file externally was a workaround for older versions and is unnecessary now, and the claim that 1.15 rejects every expression in version is out of date. An ordinary variable without const is not allowed, because module installation happens before plan-time evaluation. Data sources are read during planning, not during init, so their results cannot select which module code to download. Exam caveat: version still applies only to registry sources; a const variable does not make version valid for git sources. Operational check: run terraform init with the variable set and confirm the module installation output names the requested version.