Top 5 Enhancements in Terraform 1.15: Dynamic Module Sources and Deprecation Features

Introduction

Terraform 1.15 brings two powerful new capabilities that streamline module management and lifecycle handling. Whether you're building reusable infrastructure or maintaining mature modules, the ability to use variables in module sources and the new deprecation attributes for variables and outputs will significantly improve your workflow. In this article, we break down the top five features you need to know—from initialization‑time variables to graceful deprecation chaining. Jump to dynamic sources or jump to deprecation.

Top 5 Enhancements in Terraform 1.15: Dynamic Module Sources and Deprecation Features

1. Dynamic Module Sources with Variables

Previously, module source paths had to be static strings, which limited reuse across different environments. Terraform 1.15 now allows you to use variables directly in the source argument of module blocks, enabling dynamic sourcing based on input values. This is made possible by introducing a new const attribute for variables—when set to true, the variable's value is known during terraform init and can be interpolated into module sources. For example:

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

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

The feature extends to nested modules as long as every input variable in the chain is declared with const = true. If you reference a non‑const variable or a local in the source, Terraform will report an error during init, ensuring safety.

2. Using const = true for Initialization‑Time Variables

The const attribute is designed specifically for values that must be resolvable before any resources are planned or applied. It accepts a boolean and cannot be combined with sensitive or ephemeral—these attributes are mutually exclusive. This constraint ensures that dynamic sources remain predictable and secure. Use const when you need to select a module version, adjust module source paths per environment, or incorporate external data that is available at initialization time. The restriction against mixing with sensitive prevents accidental exposure of secret values in source URLs. By explicitly marking such variables, you gain both clarity and compile‑time checks.

3. Deprecating Module Variables Gracefully

As modules evolve, authors often need to phase out old variable names while guiding users toward replacements. Terraform 1.15 introduces a deprecated attribute on variable blocks. When a deprecated variable receives a value (via module call, CLI argument, or environment variable), a warning diagnostic is emitted during validation. Example:

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

This gives module consumers clear, early notice without breaking existing configurations. The deprecation message is displayed only when the variable is actually used, keeping output clutter minimal. For variable declarations at the root level, warnings also appear if a value is supplied through any external mechanism—helpful for detecting stale environment variables in CI/CD systems like Terraform Cloud.

4. Deprecating Module Outputs and Resources

Similar to variables, outputs can now carry a deprecated message. Referencing a deprecated output or resource from another part of the configuration triggers a validation warning. Importantly, Terraform allows “deprecation chaining”: a deprecated output can reference another deprecated output without producing a warning for the intermediate usage—only the top‑level reference triggers the diagnostic. This gives module authors a graceful path to retire outputs over multiple versions. For example:

# Inside the module
output "old" {
  value     = ...
  deprecated = "Use 'new' instead"
}

# In root module
output "ancient" {
  value     = module.myModule.old
  deprecated = "Stop using this"
}

Here, only the root output ancient produces a warning, not the module's old output, unless something else directly references it.

5. Detecting Stale Variable Values in Your Environment

One of the smartest aspects of the deprecation feature is its awareness of where a variable's value comes from. If a deprecated root variable receives a value from the command line (-var), a .tfvars file, or an environment variable, Terraform still emits a warning. This makes it easy to find and clean up legacy overrides that might otherwise linger unnoticed. Combined with the const attribute for initialization‑time variables, you can now enforce a clear separation between static configuration inputs and runtime‑only variables. The result is a more maintainable codebase where deprecation notices actively guide you toward best practices.

Conclusion

Terraform 1.15's new dynamic sources and deprecation support mark a significant step forward in module lifecycle management. By allowing variables in module sources, you can build more flexible configurations without sacrificing safety. The deprecation attributes for variables and outputs give you a structured way to evolve your modules while keeping your users informed. Experiment with these features in your next Terraform project—they'll simplify upgrades and make your infrastructure code cleaner.

Tags:

Recommended

Discover More

Data Wrangling Crisis: How Inconsistent Preparation Is Crippling Enterprise AI6 Ways Agent-Driven Development Is Transforming Coding Agent AnalysisAI Agents Gain Full Self-Service Cloud Deployment via Cloudflare-Stripe ProtocolEverything You Need to Know About the Microsoft 365 Deal: AI, Storage, and MoreHow International Law Enforcement Disrupted Massive IoT Botnets: A Step-by-Step Guide