7 Key Enhancements in Terraform 1.15: Dynamic Sources and Variable Deprecation
Introduction
Terraform 1.15 brings two major quality-of-life improvements for infrastructure-as-code practitioners: the ability to use variables in module sources (dynamic sources) and a built-in way to deprecate module variables and outputs. These features make modules more flexible and help teams manage lifecycle changes without breaking existing configurations. In this listicle, we break down the seven most important things you need to know about this release.
1. Terraform 1.15: A Focus on Flexibility and Maintainability
With version 1.15, HashiCorp introduces targeted enhancements that simplify the way you handle module sources and module lifecycle. The two headline features—dynamic module sources and variable/output deprecation—address common pain points: hardcoding source paths and making breaking changes to modules without clear warnings. These additions align with Terraform’s goal of being both powerful and safe for team collaboration.
2. Dynamic Module Sources: Variables in Source Paths
Previously, module source arguments had to be literal strings. Now you can use a variable with const = true in the source path, allowing dynamic selection of subdirectories or versioned paths during terraform init. For example, source = "./${var.folder}" works if var.folder is declared with const = true. This is especially useful for multi-environment setups where the same root module can point to different module versions without changing the configuration.
3. The const Attribute – Marking Variables for Init-Time Use
The new const attribute is a Boolean (default false) that signals a variable’s value must be known at plan time, specifically during terraform init. It cannot be used together with sensitive or ephemeral—they are mutually exclusive. Terraform enforces that only variables with const = true can be referenced in module sources, and it will error if you try to use an unmarked variable or a local. This ensures that dynamic sources remain predictable and prevent runtime failures.
4. const in Nested Modules: Propagation Rules
Dynamic sources aren’t limited to top-level modules. If a nested module declares its input variable with const = true, that variable can also be used in its own source argument. Terraform recursively checks all const declarations up the dependency tree. This allows complex multi-level module structures to remain dynamic while still enforcing that the required values are available at init time—no runtime surprises.
5. Deprecating Module Variables with the deprecated Attribute
Module authors can now mark variables as deprecated using the deprecated attribute, which accepts a string message explaining the alternative. When a deprecated variable is assigned a value (via CLI, environment, or .tfvars), Terraform emits a warning during validation. This helps users identify lingering uses and smoothly transition to new variables. For example: variable "bad" { deprecated = "Use 'good' instead" }. The warning appears only when the variable is actually used.
6. Deprecating Module Outputs Gracefully
Outputs can also be deprecated with the same deprecated attribute. When a module output is marked as deprecated, any reference to that output (e.g., module.myModule.old) triggers a warning during validation. This is especially useful when you need to rename or remove an output but want to give consumers time to update. The warning includes your custom message, making the transition clear and documented.
7. Chain Deprecation: Deprecated Outputs Referencing Deprecated Values
To support gradual migration, Terraform 1.15 allows a deprecated output to reference a deprecated value from a child module. For instance, an output ancient with deprecated = "Please stop using this" can reference module.myModule.old (also deprecated). Only one warning is emitted—at the point of reference—so module authors can deprecate a whole chain without overwhelming users with duplicate messages. This provides a smooth path for removing outdated interfaces without breaking dependent configurations.
Conclusion
Terraform 1.15’s dynamic sources and deprecation features make module management more adaptable and maintainable. By leveraging const for init-safe variables and deprecated for marking legacy elements, teams can evolve their infrastructure code with confidence. Whether you’re a module author or a consumer, these additions reduce surprises and improve the overall upgrade experience. For more details, check the official Terraform 1.15 changelog.
Related Articles
- Comprehensive Security Patches Roll Out Across Major Linux Distributions
- BleachBit Introduces Interactive TUI for Headless Server Cleaning
- Major Linux Distributions Release Critical Security Patches
- Making Transparent Huge Pages Truly Massive: The Push for 1GB Support
- Debian 14 'Forky' Implements Mandatory Reproducible Builds for Enhanced Security
- How to Recover from a Cloud Server Suspension Due to Billing Issues
- ARCTIC Fan Controller Driver Set to Debut in Linux Kernel 7.2
- Building and Testing Sealed Bootable Container Images for Fedora Atomic Desktops