AI & ML

Terraform 1.15 Introduces Dynamic Variables and Enhanced Module Management

Terraform 1.15 empowers developers with dynamic module sources, new deprecation handling, and more precise type conversions to streamline workflows.

May 13, 2026 3 min read
Sign in to save

Dynamic Module Sources

With the arrival of Terraform 1.15, practitioners are now able to leverage variables within their module sources and versions, significantly enhancing configuration flexibility. A standout feature is the introduction of the const attribute for variables, which indicates whether they can be utilized during the terraform init phase. Notably, this attribute is mutually exclusive with sensitive and ephemeral, providing clear boundaries on usage.

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

By employing the const attribute, users can define module sources flexibly:

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

The capability extends even to nested modules, assuming the respective input variables are declared with const = true. If variables or locals are referenced improperly, Terraform will signal an error during the initialization process.

Dealing with Module Variables and Output Deprecation

As module authors refine their offerings, managing deprecations becomes essential. Terraform 1.15 introduces a deprecated attribute for variables and outputs, enhancing the workflow for module lifecycle management. When deprecated variables or outputs are referenced, a warning will appear during validation, keeping developers informed of any outdated elements.

Consider the following example:

# mod/main.tf
variable "bad" {
deprecated = "Please use 'good' instead, this variable will be removed"
}
# Some module code
output "old" {
value = ...
deprecated = "Please use 'new' instead, this output will be removed"
}
# main.tf
variable "root" {
deprecated = "This should no longer be used."
}
module "myModule" {
source = "./mod"
bad = "not good"
}
locals {
moduleUsage = module.myModule.old
}
  • var.root: Users will see a diagnostic warning if any value is passed during CLI execution or environmental setup.

  • module.myModule.bad: Referencing a deprecated variable will prompt warnings from the module itself.

  • locals.moduleUsage: Diagnostics will trigger for the use of deprecated outputs.

This structured approach toward deprecation creates smoother transitions for developers updating their configurations. Furthermore, warnings are more sophisticated in their detection, delivering specific messages during planning and application processes.

Inline Type Conversions

An exciting addition in this release is the convert function, which simplifies inline type conversions. This function aims to enhance the clarity of HCL logic and mitigate errors frequently encountered in type handling.

Although Terraform usually manages type assignments effectively, edge cases can disrupt this process. Such scenarios include:

  • Conditional expressions yielding different inferred types.
  • The lack of literal syntax for certain collection types, such as maps or sets.
  • Implicit type conversions failing during equality comparisons.

Users often experience challenges when attempting to create empty containers for complex types. For instance, both {} and [] are incorrectly interpreted not as empty maps and lists but as empty objects and tuples, respectively. The convert function addresses this by allowing the explicit creation of necessary zero values.

Other Noteworthy Enhancements

Support for Windows ARM64

Terraform has officially added support for Windows ARM64 binaries, broadening its usability to devices like the Surface Pro and Windows Dev Kit 2023. This upgrade enables Terraform operation on Windows for ARM-based virtual machines running on Mac's M1/M2 architecture via Parallels, appealing to a diverse range of developers.

Improved S3 Backend Authentication

The AWS Provider for Terraform now includes support for the new aws login authentication method, which streamlines access by allowing users to leverage AWS Management Console credentials for programmatic interactions. This advancement reduces dependency on lengthy access keys and enhances security management.

Explicit Type Constraints for Output Blocks

Terraform 1.15 now allows developers to define explicit type constraints within output blocks, aligning output validation and documentation with the standards already seen in input variables.

output "string" {
type = string
value = var.some_string
}

Enhancements to Terraform Test Framework

In this version, functions can now be utilized within mock blocks in the Terraform Test framework, facilitating more effective mocking of data and resources. This feature is crucial for setting dependency values in required formats during the development and testing phases.

mock_data "azurerm_client_config" {
defaults = {
client_id = uuid()
}
}
override_resource {
target = azurerm_storage_account.example
values = {
id = format("/subscriptions/%s/resourceGroups/example/providers/Microsoft.Storage/storageAccounts/myaccount", uuid())
}
}

Variable Validation Blocks in Stacks

As part of the ongoing development of the Stacks ecosystem, this release integrates validation blocks for variables as a CLI feature. This addition includes condition and error_message attributes, enabling users to enforce specific criteria early in the configuration process.

variable "prefix" {
type = string
validation {
condition = length(var.prefix) > 5
error_message = "prefix must be longer than 5 characters."
}
}

Looking Ahead

For those excited to leverage the capabilities of Terraform 1.15, getting started is straightforward:

This release underscores the ongoing collaboration and feedback from the community, driving continual enhancement of Terraform. For detailed changes, check the complete Terraform 1.15 changelog.

Source: Apoorva Murthy · www.hashicorp.com

Comments

Sign in to join the discussion.