terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Allow version to be variable in (sub)modules

Open wjvanroosmalen opened this issue 3 years ago • 21 comments

I would like to have default sub module version and a variable input for submodules.

A solution could look like this:

module "solution" {
  source  = "app.terraform.io/customer/solution"
  version = "1.1.5"
  global_settings = var.global_settings
  account_id = var.global_settings.account_id

  networking_module_version = var.networking_module_version
  application_module_version = var.application_module_version
}

variable "networking_module_version" {
 default = "1.0.0"
}

variable "application_module_version" {
 default = "1.0.0"
}

Currently I need to update my solution module's submodule dependencies when they update. However, I would like to:

  1. constrain my team that deploy solution to use certain defaults but,
  2. allow differences between deployments that rely on changes in submodules.

Not sure if this is currently possible. It looks like it is not.

Current Terraform Version

0.15.2

Use-cases

Attempted Solutions

Proposal

References

wjvanroosmalen avatar Jun 09 '21 12:06 wjvanroosmalen

Upvote! Currently tf throws "Variables not allowed: Variables may not be used here.", when you try to feed version from a var or local. It would be nice to allow this, so we can bind a certain version as variable default, but leave the freedom for consumers to use older or preview/beta versions.

Ledermayer avatar Sep 27 '21 15:09 Ledermayer

+1

zparnold avatar Oct 13 '21 13:10 zparnold

+1

thiagolsfortunato avatar May 05 '22 20:05 thiagolsfortunato

Thanks for your interest in this issue! This is just a reminder to please avoid "+1" comments, and to use the upvote mechanism (click or add the 👍 emoji to the original post) to indicate your support for this issue. Thanks again for the feedback!

crw avatar May 12 '22 20:05 crw

I am trying to solve a slightly different problem: promoting module versions across environments without requiring a module to wrap the entire stack definition.

There are a variety of pre-processors that can be used as workaround: Terrafile, Terraspace custom helpers, and Terramate generation.

cgetzen avatar Aug 07 '22 21:08 cgetzen

without requiring a module to wrap the entire stack definition.

Hey @cgetzen , interesting pointers to aforementioned solutions, but what do you mean by this?

dimisjim avatar Aug 07 '22 22:08 dimisjim

+1

ncapps avatar Oct 25 '22 20:10 ncapps

@ncapps please upvote the original comment ;-) +1 in a comment is not counted

dgillman avatar Oct 25 '22 22:10 dgillman

I would already be pleased with a static local. E.g.

module "ref1" {
  source  = "somemodulereference"
  version = local.moduleversion
  ...
}

terraform
module "ref2" {
  source  = "somemodulereference"
  version = local.moduleversion
  ...
}

terraform
module "ref3" {
  source  = "somemodulereference"
  version = local.moduleversion
  ...
}

locals {
    moduleversion = "5.6.3"
}

I believe static locals would resolve fine during the init phase.

In Terraform cli's current version 1.3.3 this throws errors:

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Error: Variables not allowed
│
│ On main.tf line 3: Variables may not be used here.
╵

╷
│ Error: Unsuitable value type
│
│ On main.tf line 3: Unsuitable value: value must be known
╵

cveld avatar Nov 02 '22 13:11 cveld

It's already 2 years now. I guess they will never work on this issue.

lquanx avatar May 18 '23 13:05 lquanx

Any Update on this issue .

maha51ece-tech avatar Aug 15 '23 09:08 maha51ece-tech

Is there any update on the following?

GISTech01 avatar Sep 12 '23 07:09 GISTech01

Would love to see this feature. Now I understand why people are creating two different code bases for dev and prod and why Google has it as their Best Practice, Do we have any updates on this?

Schillman avatar Nov 09 '23 09:11 Schillman

Any update on this issue. Look forward to this feature, too.

shreychen avatar Jan 19 '24 14:01 shreychen

Is there a way to do this already, that's just not as clear?

It's getting to the point where I'm about to build my terraform files from jinja2 templates instead writing them directly.

draeath avatar Jan 26 '24 21:01 draeath

any news? 👀

thiagolsfortunato avatar Mar 08 '24 18:03 thiagolsfortunato

We have the same issue. This is a major blocker for us. I need to allow passing variables to module calls for version. Same issue as here: https://github.com/hashicorp/terraform-provider-tfe/issues/849

module "example" {
  source               = "app.terraform.io/XXXX/eks-cluster/aws"
  version              = var.module_version # <-- support this please
}

Satak avatar Mar 21 '24 12:03 Satak

+1

alexanderogorodnikov avatar Mar 22 '24 18:03 alexanderogorodnikov

This would help a lot! I for example have multiple times to use the same module with version xxx and I have to maintain all these places. Please provide this feature.

ahoehma avatar Mar 29 '24 08:03 ahoehma

Would love to see this feature. Now I understand why people are creating two different code bases for dev and prod and why Google has it as their Best Practice, Do we have any updates on this?

Frankly, Google's branches per environment is a terrible practice.

dcherniv avatar May 06 '24 18:05 dcherniv

Would love to see this feature. Now I understand why people are creating two different code bases for dev and prod and why Google has it as their Best Practice, Do we have any updates on this?

Frankly, Google's branches per environment is a terrible practice.

Wasn't referring to that, was referring to their not so DRY friendly way of working. Where they have several codebases for each environment. Never heard of Googles way of working when it comes to dedicated branches per environment. Do you have any source on that?

Schillman avatar May 06 '24 20:05 Schillman