Skip to content

variable/expression references in module source attribute #36880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jan-g opened this issue Apr 14, 2025 · 1 comment
Open

variable/expression references in module source attribute #36880

jan-g opened this issue Apr 14, 2025 · 1 comment
Labels
enhancement new new issue not yet triaged

Comments

@jan-g
Copy link

jan-g commented Apr 14, 2025

Terraform Version

All

Use Cases

I'm interested in deployments across multiple cloud providers. By-and-large the TF for these are the same, with some features varying.

I'm particularly interested in being able to write multiple modules that conform to the same interface, with implementations selected on the basis of a variable value.

Attempted Solutions

This is not something that can currently be done within terraform.

Proposal

It'd be great if this would work:

# main.tf
variable "platform" {
  type = string
  default = "p1"
}

module "m" {
  source = "./module/${var.platform}"
  x = 10
}

output "y" {
  value = module.m.y
}

# module/p1/main.tf
variable "x" {
  type = number
}

output "y" {
  value = var.x + 1
}

# module/p2/main.tf
variable "x" {
  type = number
}

output "y" {
  value = var.x * 2
}

I'd be happy with variables / expressions computed from locally-available values (eg, selecting the module to use from a yaml config file).

References

@jan-g jan-g added enhancement new new issue not yet triaged labels Apr 14, 2025
@crw
Copy link
Contributor

crw commented Apr 14, 2025

Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants