Codenil

What's New in Terraform 1.15: Dynamic Module Sources and Deprecation Support

Published: 2026-05-17 20:52:11 | Category: Linux & DevOps

Terraform 1.15 introduces two major enhancements that streamline module management: the ability to use variables in module sources (opening up dynamic module references) and a formal deprecation system for variables and outputs. These features help practitioners write more flexible, maintainable code while easing the upgrade path for module authors. Below, we break down the key changes through a series of questions and answers.

How do dynamic module sources work in Terraform 1.15?

In earlier versions, module source URLs had to be static – you couldn't use variables to reference different folders or registries. Terraform 1.15 introduces the const attribute for variables, which signals that the variable can be used during terraform init. When you set const = true on a variable, Terraform treats it as a compile‑time constant that can appear in a module's source argument. For example:

What's New in Terraform 1.15: Dynamic Module Sources and Deprecation Support
variable "folder" {
  type  = string
  const = true
}

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

This allows you to parameterize module sources across environments or configurations. The constant variable cannot be combined with sensitive or ephemeral attributes – they are mutually exclusive. If you reference a non‑const variable or a local in a module source, Terraform will raise an error during init.

Can I use const variables in nested modules?

Yes, the functionality extends to nested modules. For a nested module to accept a const variable in its source, the module author must explicitly declare the input variable with const = true. Terraform validates this during terraform init. This gives you a way to propagate dynamic module sources through a hierarchy, as long as every module in the chain marks the relevant variable as constant. Without that explicit declaration, Terraform will report an error, ensuring you don’t accidentally use a non‑constant value in a place that requires compile‑time resolution.

How do I deprecate a variable in Terraform 1.15?

Module authors can now add a deprecated attribute to a variable block. This attribute accepts a string message explaining why the variable is deprecated and what to use instead. For instance:

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

When a user passes a value to this deprecated variable – whether via a module call, CLI arguments, or environment variables – Terraform will emit a warning diagnostic during validation. This helps users identify any lingering references in their configurations or automation tools like Terraform Cloud. The deprecation message is shown alongside the warning, giving clear guidance for migration.

How do I deprecate an output in Terraform 1.15?

Similarly to variables, outputs can now have a deprecated attribute. When you mark an output as deprecated, Terraform issues a warning whenever it is referenced elsewhere – for example, in a locals block, another module’s input, or a root output. Example:

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

If someone references module.myModule.old in a local or output, they will see a diagnostic warning. This allows module authors to smoothly phase out outputs without breaking dependent configurations. Importantly, deprecated outputs can still reference other deprecated values without triggering additional warnings – the system is designed to avoid cascading noise during gradual deprecation.

Can I reference a deprecated output from another deprecated output?

Yes, Terraform 1.15 deliberately allows this to support gradual migration. If you have a deprecated output that references a deprecated resource or sub‑output, only the use of the outermost deprecated output triggers a warning. For example:

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

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

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

Here, referencing module.myModule.old in the deprecated ancient output does not add an extra warning. The warning only appears when someone uses ancient in their configuration. This prevents a cascade of duplicate warnings and makes it easier to chain deprecations over multiple releases.

What diagnostic warnings do I see in Terraform 1.15 for deprecated items?

Terraform emits a warning diagnostic during terraform validate (or plan/apply) for each deprecated variable or output that is actively used. Consider this example:

  • A root variable root marked deprecated: if a value is passed via CLI or environment variable, a warning appears.
  • A module call bad = "not good" where bad is a deprecated variable: a warning is issued for that module argument.
  • A local referencing a deprecated output: the local declaration triggers a warning.
  • If a resource itself is deprecated, referencing it anywhere (e.g., in a local) also produces a warning.

These deprecation warnings help users identify all places where they are relying on deprecated elements, making upgrades safer and less disruptive.

How does const relate to sensitive and ephemeral attributes?

The const attribute is mutually exclusive with both sensitive and ephemeral. You cannot mark a variable as both constant and sensitive (or constant and ephemeral). This constraint exists because constant variables are used at compile time (during terraform init) and their values must be known before any sensitive handling or ephemeral lifecycle logic applies. If you need a variable that is both constant and sensitive, you’ll need to manage it through other means – for example, by using a separate secure parameter store and referencing it as a regular (non‑constant) variable.