-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
terraform get: can't use variable in module source parameter? #1439
Comments
Is there any particular reason behind that? Do you expect some modules to have the same interface, so you can swap these? |
This is as intended. We should add validation that this isn't allowed. The reason is simply that it breaks our compile -> semantic check -> execute loop. i.e. imagine if your C code could arbitrarily download new C files during compile/execution. Would be weird. |
yes, that is exactly my point - for the flexible running plans against various versions/forks of identically interfaced modules, without refactoring base terraform code |
Er. Forgive me - I'm lost here, due to labels - that is - marked bug, yet your comment suggest a wontfix |
The fix is to add the validation so you get something a bit more clear rather than |
FWIW, this is something I wanted to do as well and found wasn't supported. In my case, I wanted to avoid duplicating |
Also to set the branch/tag via a variable would be helpful... |
See #1145 |
@radeksimko I'm familiar with ref as added in a recent version, but I'm suggesting something like Are variables allowed at all in modules sources? |
@clstokes They're not yet |
+1 on this. I want admins and automated-ci to be able to specify the local path, allow flexibility to pull from git or filesystem, etc, but this is not possible without allowing interpolation in the source param. |
This is not a bad idea but it is very hard to do with the current architecture of how modules work with Terraform. It also shifts a lot of potential errors away from a compile-time error to a runtime error, which we've wanted to avoid. I'm going to keep this tagged with "thinking" |
@mitchellh, how are compile-tile and runtime differentiated in Terraform? Are you referring to Said another way, TF as it is right now gives me a lot of compile time and runtime errors. For example, you can easily tell TF to create an SSH key that seems fine with |
+1, I understand why this may be architecturally tricky to get right, but it would be great to have on the admin/DRY side of things. |
+1 I also think that the gained flexibility would outweigh the disadvantages. |
👍 Use-case for this would be allowing for the flexibility to store module source in a variable for : a. module source pointing at a corporate source control behind a corporate VPN variable "your_project_source" {
default = "https://your_src_system/your_project//terraform"
} OR variable "your_project_source" {
default = "/Users/joeshmoe/projects/your_project/terraform"
} (and overriding one or the other in terraform.tfvars) and then module "your_project" {
source = "${var.your_project_source}"
...
} |
One very specific complexity with this is that currently modules need to be pre-fetched using Perhaps in some cases this could be worked around by breaking a configuration into two separate runs, with an initial run creating a remote state that can be consumed by the second run. Since This is of course not as convenient as creating everything in one step using directly-referenced modules, but maybe it's a reasonable workaround for some situations in the mean time. |
@kokovoj 's use-case, of switching to a different version in a development environment, got me thinking about how that gets solved in other languages. When I have a problem like that in e.g. Go, NodeJS or Python I don't use any runtime features to solve it, but rather I just ignore the location/version of the module given in the dependency list and just install whatever one I want, exploiting the fact that (just like in Terraform) the "get" step is separated from the "compile" and "run" steps, and so we can do manual steps in between to arrange for the versions we want. Terraform obscures this ability a little by storing the local modules in a directory named after the MD5 hash of the module name under the So with all of this said, perhaps Terraform could just be a little more transparent about where it looks for modules and embrace the idea that (It would also be nice to extend |
Personally I'd love to see interpolation for the entire source parameter. The chosen direction to implement support for just the version is very limiting. I'd rather like to pull all my source definitions to the top of a configuration, in a locals definition, so I don't have to go hunting through every file to find/update the string. I expect it would make modules much more maintainable overall. |
@lorengordon I agree.. this is nonsense.. that and the fact that everytime you pull a whole repository instead of a leaf |
We use this http://bensnape.com/2016/01/14/terraform-design-patterns-the-terrafile/ I think it would be reasonable to have something like that natively. |
@mitchellh - It would be great if hashicorp could re-look at this. Though it's been closed, and split into two cases, which don't address all the reasons for this, it's more commented then any current open issue. |
The best workaround I have found is by using putting something like this in override.tf module "core" {
source = "/Users/dev/terraform-modules/core"
}
... Not ideal, but seems to work. |
@mitchellh agreement with @jjshoe the original issue of allowing interpolation for the source parameter has not been addressed. This issue should be opened, or a new one forked off. But it should not be closed. |
@akvadrako I'm not following your workaround. Can you elaborate? |
@MichaelDeCorte It's just that it's possible to override the module |
@mitchellh elaborating an example to allow the for absolute paths relative to TF-Home. Assume the below directory / file structure. This is a common pattern where repo1 is a shared repository that is downloaded locally via a script as a workaround for the source interpolation issue. TF-Home /
Assume that app1, app2 and foo1.tf all depend on foo2. The source parameter would be: I hope it's clear that its not great. |
@akvadrako Our powershell wrapper does so many things to over come terraform restrictions, we cant use terraform without, basically we did something like the guys in terragrunt did, plus many more addons on it, i cant understand how somebody can even use terraform as is out of the box without some interpolation in those missing places.. anyhow, i really hope hashicorp will decide to change some parts of the product, because it is really constricting, some of those things should have been thought of much before |
Yeah, we've been using the |
The rationale to disallow this so that intelligent people can't download random modules is the same as not having a division operator as somebody may decide to divide by zero one day. |
+1. Changing module versions manually is error prone. |
How else can you do it. :o
…On Sat, Oct 20, 2018, 10:17 AM Matthew Tuusberg ***@***.***> wrote:
+1. Changing module versions manually is error prone.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1439 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADxtkMTqJSkZ98V__pZRc_eVZVqyMbZfks5umzBjgaJpZM4D9Dyw>
.
|
There is a similar issue in not being able to use interpolation syntax when providing configuration for back ends (say S3 bucket/region). You get around that by using terraform init -backend-config so that value is known at the beginning of the lifecycle. Couldn't something be done similarly (provide the value as some kind of command line param)? |
This is something I've been wanting for a while and have been thinking a lot about. The use case I have is I wrote a bunch of terraform code to deploy a kubernetes cluster. In my code I have a variables module which lives in a git repo and contains all my input variables based on region and environment. This allows me to use the same exact code to deploy my kubernetes cluster to multiple AWS account and into multiple regions and environments with only changing two inputs to |
I need to be able to pass variable. Is Hashcorp looking to resolve this issue? |
With workarounds being provided and they intentionally made it this way, not likely we will see parameters in the source line.
I recommend using different folder paths and wiring up all relative pathing in your TF files.
From: josephcaxton <notifications@github.com>
Reply-To: hashicorp/terraform <reply@reply.github.com>
Date: Wednesday, December 5, 2018 at 6:30 AM
To: hashicorp/terraform <terraform@noreply.github.com>
Cc: Garin Kartes <Garin.Kartes@alaskaair.com>, Comment <comment@noreply.github.com>
Subject: Re: [hashicorp/terraform] terraform get: can't use variable in module source parameter? (#1439)
I need to be able to pass variable. Is Hashcorp looking to resolve this issue?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgh.neting.cc%2Fhashicorp%2Fterraform%2Fissues%2F1439%23issuecomment-444504173&data=02%7C01%7Cgarin.kartes%40alaskaair.com%7C1692108d43a74281574e08d65abe4217%7C0f44c5d442b045c2bf55d0fea8430d33%7C1%7C0%7C636796170540379315&sdata=44aW3hZTTeccEDntjYPI03TeU11tqXtlJSKfJThwknk%3D&reserved=0>, or mute the thread<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgh.neting.cc%2Fnotifications%2Funsubscribe-auth%2FARwnyDDvgV-3yvBNCAQes2gsVqzbYiZNks5u19iXgaJpZM4D9Dyw&data=02%7C01%7Cgarin.kartes%40alaskaair.com%7C1692108d43a74281574e08d65abe4217%7C0f44c5d442b045c2bf55d0fea8430d33%7C1%7C0%7C636796170540389334&sdata=99pGIuhS1Td8MJQahoDjOJnsCWJGguO6x9amTi4BZco%3D&reserved=0>.
|
While I can understand the reasons for not supporting general var/local inclusion .. I feel that many (all?) of the above use cases could be resolved by adding |
Or even something like source |
Another example as to why this is beneficial: `####################### Global value ####################### ###################### } this would be called acmecorp.tf, we would just copy this module and renamed it to loonytoons.tf and change the local var to loonytoons thus saving a lot of copy pasta |
Adding to a comment by richardgavel from Nov 14, 2018 Backend configuration is stored in Having such feature is particularly useful if you want to test new module version which is located in some feature branch in another (shared) repo, you then have to edit all paths to module manually and re-init anyways. |
+1 for this. I have a git-based module to configure team permissions, and I have ~80 teams. That's a lot of wet, brittle code that won't stand up to any significant change in the repository structure. If we cannot have the |
A use I see easily popping up (in that literally my first project that I'm working on terraform with), I want to have multiple modules that I pull from, but I will always want those to use same branch, within a project: prod_git_tag = "v.0.0.1"
staging_git_tag = "v.0.5.7" and then module "vpc" {
source = "${git_repo_path}?ref=${git_tag}"
}
module "kubernetes-cluster" {
source = "${git_repo_path}?ref=${git_tag}"
}
# etc... which seems pretty reasonable to me - when I pass in |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
I'm trying to avoid hard-coding module sources; the simplest approach would be:
The result I get while attempting to run
terraform get -update
isThe text was updated successfully, but these errors were encountered: