Damfinos
ArticlesCategories
Linux & DevOps

Terraform 1.15 Introduces Dynamic Module Sources and Variable Deprecation: Key Updates

Published 2026-05-14 15:49:10 · Linux & DevOps

Overview

Terraform 1.15 brings two significant enhancements that improve module flexibility and lifecycle management. First, practitioners can now use variables within module sources and versions, enabling more dynamic configuration structures. Second, module authors gain the ability to deprecate variables and outputs with clear warnings, easing the transition for users. These features streamline infrastructure as code workflows while maintaining backward compatibility.

Terraform 1.15 Introduces Dynamic Module Sources and Variable Deprecation: Key Updates

Dynamic Module Sources with const Variables

Prior to Terraform 1.15, module sources had to be static strings, limiting reusability. With this release, you can now reference variables in your module source paths, but only if the variables are declared with the new const attribute. This attribute accepts a boolean (true or false) and indicates that the variable value is known during terraform init—unlike other variables that may depend on plan-time data.

How It Works

Declare a variable with const = true:

variable "folder" {
  type  = string
  const = true
}

Then use it in a module source:

module "zoo" {
  source = "./${var.folder}"
}

This capability extends to nested modules, as long as each intermediate input variable also uses const = true. If you attempt to reference a non-const variable or a local value in a module source, Terraform will report an error during init.

Constraints

Note that const cannot be combined with sensitive or ephemeral attributes—they are mutually exclusive. This ensures that the value used for source resolution is always plain text and available at initialization time.

Module Variable and Output Deprecation

As modules evolve, authors often need to phase out older variables and outputs. Terraform 1.15 introduces a deprecated attribute for both variable and output blocks. When a deprecated element is used or referenced, a warning diagnostic is emitted during validation.

Deprecating a Variable

Inside your module, you can mark a variable as deprecated:

variable "bad" {
  deprecated = "Please use 'good' instead, this variable will be removed"
}

If a user passes a value to this variable (via CLI, environment variable, or configuration), Terraform will issue a warning. Similarly, you can deprecate an output:

output "old" {
  value = ...
  deprecated = "Please use 'new' instead, this output will be removed"
}

References to deprecated outputs trigger diagnostics, as shown in this example:

# main.tf
variable "root" {
  deprecated = "This should no longer be used."
}

module "myModule" {
  source = "./mod"
  bad    = "not good"
}

locals {
  moduleUsage = module.myModule.old
}

This code produces warnings for var.root (if a value is provided), module.myModule.bad, and locals.moduleUsage.

Gradual Deprecation of Outputs

To help module authors manage deprecation gradually, Terraform allows deprecated outputs to reference other deprecated outputs. In such cases, only one diagnostic warning is emitted—at the outermost deprecated reference. This avoids cascading warnings while still signaling the eventual removal.

Example:

# mod/main.tf
output "old" {
  value = ...
  deprecated = "Please use 'new' instead"
}

# main.tf
module "myModule" {
  source = "./mod"
}

output "ancient" {
  value = module.myModule.old
  deprecated = "Please stop using this"
}

Here, only the reference to output.ancient will produce a warning, not the use of module.myModule.old inside it. This design enables clean migration paths for downstream consumers.

Conclusion

Terraform 1.15's dynamic module sources and deprecation features give teams more control over configuration reuse and module evolution. The const variable attribute unlocks flexible source paths while maintaining safety during initialization. Meanwhile, the deprecated attribute provides a standardized way to communicate upcoming changes, reducing surprises and improving collaboration. Upgrade to Terraform 1.15 to leverage these capabilities in your infrastructure workflows.