Skip to content
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

Allow capturing and passing module source as a variable #33793

Open
MOZGIII opened this issue Sep 4, 2023 · 3 comments
Open

Allow capturing and passing module source as a variable #33793

MOZGIII opened this issue Sep 4, 2023 · 3 comments
Labels
enhancement new new issue not yet triaged

Comments

@MOZGIII
Copy link

MOZGIII commented Sep 4, 2023

Terraform Version

Terraform v1.5.2

This is irrelevant because this issue is like 10 years old now.

Use Cases

Can be a solution for people who want variable support in module sources.

Attempted Solutions

Variables in modules sources - was rejected because modules need to be installed as dependencies before they can be used. This makes sense.

Proposal

Allow doing this:

  • In the module qq

    variable "qwe" {
      type = module_source
    }
    
    module "abc" {
      source = var.qwe
    }
  • Outside of the module:

    module_source "qwe" {
      source = "./qwe" # could also be git: or any other source
      # only source is allowed, and no instance of the module is created here - just the module source is loaded and made available for other variables
    }
    
    module "qq" {
      source = "./qq"
    
      abc = module_source.qwe
      # other parameters that "qq" mod accepts
    }

The version of qwe is locked and specified in the outside module.

References

@MOZGIII MOZGIII added enhancement new new issue not yet triaged labels Sep 4, 2023
@crw
Copy link
Contributor

crw commented Sep 7, 2023

Thanks for this feature request! This issue looks fairly close to #25587 -- do you think this is a use case of that issue, or an alternate implementation?

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!

@crw crw added the waiting-response An issue/pull request is waiting for a response from the community label Sep 7, 2023
@MOZGIII
Copy link
Author

MOZGIII commented Sep 7, 2023

This is exactly in relation to that issue, but this is an alternative approach that is actually doable, in contrast to the approach that people want at #25587 and similar issues (there are severe architectural issues that have been blockers for like 10 years now and there is no solution in sight).


If we had #25587 implemented - we would not need this, but if we don't have #25587 this is much more practical. I suspect the only way to actually implement #25587 is to do what I suggest here, but it is not clear just yet.
We can have both this and #25587 (i.e. one does not supersede/replace the other) as the niche use cases are different, but for what I need to do in my more general use case both this and #25587 would be sufficient (there is no way #25587 will be implemented though since it is the same as the eight-year-old #1439).

@crw crw removed the waiting-response An issue/pull request is waiting for a response from the community label Sep 8, 2023
@ghazanhaider
Copy link

Adding my voice here. We use Terraform Cloud extensively across multiple teams and have shared modules in github repositories. Version tracking is almost impossible except manually.. and it is not just the base code but all previous Terraform Cloud workspaces that were deployed have to be version-pinned per module.

Terraform cloud also does not allow a pre-init script, and the pre_plan key does not work for this. There's no clear mechanism between github and Terraform Cloud where scripts can be added to replace these versions before terraform runs.

Any mechanism that allows a module source to be dynamically specified in terraform code will be welcome.

A mechanism that can substitute variables (or environment variables) in the git path or ref will be particularly helpful.

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

3 participants