Terraform 1.15: Dynamic Module Sources and Improved Deprecation Management
Introduction
Terraform 1.15 brings two significant enhancements that give practitioners more flexibility and control over their infrastructure-as-code workflows. The new release introduces dynamic module sources powered by a const variable attribute, and a streamlined deprecation mechanism for variables and outputs. These features help teams manage module dependencies more dynamically and phase out legacy configurations with clear warnings. Below we dive into each capability and how to use them effectively.
Dynamic Module Sources with Const Variables
Previously, module sources in Terraform had to be static strings. With version 1.15, you can now use variables within module sources—but only if those variables are marked with the new const attribute. The const attribute takes a boolean value (true or false) and signals that the variable is safe to evaluate during terraform init. Importantly, const cannot be used together with sensitive or ephemeral; they are mutually exclusive.
Example variable declaration:
variable "folder" {
type = string
const = true
}This variable can then be referenced in a module source:
module "zoo" {
source = "./${var.folder}"
}Using Const in Nested Modules
The dynamic source capability extends to nested modules as well. For a nested module to accept a dynamic source, every input variable that is used in that module’s own source must be explicitly declared with const = true. This ensures that the entire chain of module dependencies can be resolved at initialization time.
Validation During Init
Terraform will report an error during terraform init if you attempt to use a variable or local that is not marked as const in a module source. This safeguard prevents runtime surprises and enforces that only predictable, static-like values are allowed during initialization.
Managing Deprecation of Variables and Outputs
As module authors evolve their modules, they often need to deprecate older variables and outputs to guide users toward newer alternatives. Terraform 1.15 introduces a deprecated attribute for both variable and output blocks. When a deprecated variable or output is used, Terraform emits a warning diagnostic during validation, helping users identify and update their configurations.
The deprecated Attribute
The deprecated attribute accepts a string message explaining why the item is deprecated and what to use instead. Example for a variable:
variable "bad" {
deprecated = "Please use 'good' instead, this variable will be removed"
}And for an output:
output "old" {
value = ...
deprecated = "Please use 'new' instead, this output will be removed"
}Diagnostic Warnings in Practice
Warnings are issued in several scenarios:
- Root variable with
deprecated: If a value is passed for a deprecated root variable (via CLI arguments, environment variables, or other means), a warning is emitted. This helps verify that no lingering values remain in the environment. - Module call with deprecated variable: When a module call passes a value to a deprecated input variable, the warning appears.
- Reference to deprecated output: Using a deprecated output in a
localor another output triggers a warning. - Reference to deprecated resource: If a resource is deprecated, a warning is emitted when it is referenced.
Consider the following example:
# mod/main.tf
variable "bad" {
deprecated = "Please use 'good' instead"
}
output "old" {
value = ...
deprecated = "Please use 'new' instead"
}
# main.tf
variable "root" {
deprecated = "This should no longer be used."
}
module "myModule" {
source = "./mod"
bad = "not good"
}
locals {
moduleUsage = module.myModule.old
}Running terraform validate would produce warnings for var.root (if a value is passed), module.myModule.bad, and locals.moduleUsage.
Gradual Deprecation with Chained Deprecated Outputs
To allow module authors to phase out deprecated outputs gradually, Terraform 1.15 permits referencing a deprecated output inside another deprecated output without triggering a separate warning. The warning is only emitted for the outermost deprecated reference. For 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"
}In this case, using output.ancient will only produce a single warning about ancient, not an additional warning about old. This makes it easier for module authors to provide a migration path without overwhelming users with duplicate warnings.
Conclusion
Terraform 1.15 empowers practitioners with dynamic module sources through const variables, enabling more flexible and reusable module configurations. At the same time, the new deprecated attribute for variables and outputs gives module authors a clear, standardized way to communicate lifecycle changes. Together, these features improve the developer experience by reducing friction during initialization and easing the transition to updated module versions.
Related Articles
- Mozilla’s For-Profit Arm Unveils Thunderbolt: Open-Source ‘Sovereign AI’ for Enterprises
- Alphabet Makes Record Yen Bond Sale as AI Spending Surge Drives Global Capital Race
- Meta's AI-Powered Efficiency: How Automated Agents Optimize Hyperscale Infrastructure
- Ubuntu Under Siege: 6 Critical Insights into the DDoS Attack and Twitter Compromise Leading to a Crypto Scam
- Fedora KDE Plasma Desktop Edition 44: A Refined Experience with Plasma 6.6 and Streamlined Setup
- Linux 7.2 Brings Mainline Support for Realtek RTL8159 10GbE USB Adapters
- How to Upgrade to Ubuntu 26.04 LTS: A Step-by-Step Guide
- Kubernetes v1.36 Debuts Production-Grade PSI Metrics: A New Era for Node-Level Observability