Terraform 1.15: Dynamic Module Sources and Deprecation Support
Introduction
Terraform 1.15 arrives with two major quality-of-life improvements: the ability to use variables in module sources and a structured way to deprecate module variables and outputs. These features help practitioners write more flexible configurations and give module authors a clear path to evolve their modules over time. Below we dive into each enhancement with practical examples.
Dynamic Module Sources with Variables
Previously, module sources had to be static strings—you could not use variables or locals. Terraform 1.15 changes that by introducing the const attribute for input variables. When a variable is declared with const = true, it signals that its value will never change after initialization, making it safe for use during terraform init. This variable cannot be marked as sensitive or ephemeral; those attributes are mutually exclusive.
variable "folder" {
type = string
const = true
}
With such a variable, you can now do this in your root module or a child module:
module "zoo" {
source = "./${var.folder}"
}
Nested Modules and Constraint Propagation
Dynamic sources also work in nested modules, as long as every intermediate dependency—each variable used to construct the source path—is itself declared with const = true. If you try to use a non-const variable or a local in the source, Terraform reports an error during initialization, preventing ambiguities.
Module Variable and Output Deprecation
Module authors often need to phase out old variables or outputs. In Terraform 1.15, both variable and output blocks gain a new deprecated attribute. When set to a string message, any use of that variable or reference to that output triggers a warning diagnostic during terraform validate or plan.
Deprecating Variables
Consider a module that has an old variable bad. You can mark it as deprecated:
# mod/main.tf
variable "bad" {
deprecated = "Please use 'good' instead, this variable will be removed in v2.0."
}
If a root module passes a value to bad, Terraform emits a warning with the deprecation message. Similarly, if a root variable root is deprecated and a value is supplied through CLI arguments or environment variables, a diagnostic is generated—helping you clean up leftover configuration.
Deprecating Outputs
Outputs can also be deprecated. For example:
# mod/main.tf
output "old" {
value = aws_instance.example.arn
deprecated = "Use 'new' output instead. Will be removed in next major version."
}
Any root module referencing module.myModule.old will see a warning. This makes it easy to notify consumers of the module without breaking their configurations immediately.
Managing Deprecation Gradually
To give module authors even more flexibility, deprecated outputs can be used as values for other deprecated outputs. This allows you to chain deprecation warnings while still providing backward-compatible data. For example:
# mod/main.tf
output "old" {
value = aws_instance.example.arn
deprecated = "Use 'new' output."
}
# main.tf
module "myModule" {
source = "./mod"
}
output "ancient" {
value = module.myModule.old
deprecated = "Please stop using this; migrate to module output 'new'."
}
In this setup, a user referencing output.ancient will see a single warning about ancient. The inner deprecation of old is not reported again, preventing redundant messages. This lets you deprecate at multiple levels while keeping the user experience clean.
Conclusion
Terraform 1.15 empowers practitioners with dynamic module sources (using the const attribute) and a deprecation system for variables and outputs. These features make it easier to write reusable, maintainable infrastructure code and smoothly migrate configurations as modules evolve. Upgrade to 1.15 and start using these enhancements today.
Related Articles
- Meta's AI Agents Revolutionize Hyperscale Efficiency: Hundreds of Megawatts Recovered
- Exploring Sealed Bootable Container Images for Fedora Atomic Desktops: A Q&A Guide
- Linux This Week: Standard Projects Folder, Firefox Ad-Blocker, and Major Distro Updates
- 6 Key Facts About Linux Mint's HWE ISOs and Why They Matter
- Policy Groups: A New Approach to Memory Management Beyond Control Groups
- Unveiling Latest Terraform Enhancements: Cost Insights, Project Controls, and More
- AMD Drops Surprise HDMI 2.1 FRL Patches for Linux GPU Driver—Higher Bandwidth on the Horizon
- Linux 7.2 Kernel to Adopt 'Fair' DRM Scheduler Priority, Adds AIE4 Support for AMDXDNA