Terraform: Referencing to a module in a peer directory using relative path with `..\other_module`

Created on 27 Sep 2017  ยท  4Comments  ยท  Source: hashicorp/terraform

Terraform Version

0.10.6

Terraform Configuration Files

n/a

Debug Output

Get: git::ssh://[email protected]/org/utils?ref=v0.1.0//to_qualified_name
Get: git::ssh://[email protected]/org/utils?ref=v0.1.0//to_tags
Error loading modules: module tag_qname: invalid source string: ../to_qualified_name

Crash Output

n/a

Expected Behavior

We have a single git repo that contains a collection of modules that are in subdirectories. The idea is to not have to create a repo for a collection of very small modules that mainly transform input variables into output. Some of these modules use each other, so within these modules, there are references to peer folders. For example:

module "tag_qname" {
  source                = "../to_qualified_name"
  environment           = "${var.environment}"
  name                  = "${var.name}"
}

In 0.9.x this was working. In 0.10.x, we now get error above. It seems that terraform is downloading github subdir sources are standalone modules under .terraform/modules and no longer can modules that come from a single git repo able to reference each other.

Actual Behavior

Get the error under Debug Output

Steps to Reproduce

  1. Create a repo that contains 2 modules
  2. Have module A user module B by sourcing it using relative path ../moduleB
  3. Create an external main.tf that brings in module a from git repo
    <repo url>?ref=version//moduleA
  4. Do a terraform get and see the error about moduleA not able to find ../moduleB

Important Factoids

Used to work in 0.9.x!!!

References

n/a

Most helpful comment

I confirm this was working until 0.10.5 version but after some changes on the terraform/config/module/tree.go it stopped working

Diff: https://github.com/hashicorp/terraform/compare/refs/tags/v0.10.5...refs/tags/v0.10.6

Previous behaviour (<= 0.10.5)

Module Source:

source = "[email protected]:org/repo.git?ref=v1.1.1//terraform/"

.modules folder:
screen shot 2017-09-28 at 1 57 23 pm

Actual behaviour (>= 0.10.6)

Module Source:

source = "[email protected]:org/repo.git?ref=v1.1.1//terraform/"

.modules folder:

screen shot 2017-09-28 at 2 01 28 pm

Conclusion

Before 0.10.6 it was cloning the entire repo instead of just the folder where the terraform module source resides. This is particularly used when using relative folder references such as:

# -- VERSION
output "version"  { value = "${file("${path.module}/../VERSION")}" }

All 4 comments

It also used to work in 0.10.2. Is this a regression?

I confirm this was working until 0.10.5 version but after some changes on the terraform/config/module/tree.go it stopped working

Diff: https://github.com/hashicorp/terraform/compare/refs/tags/v0.10.5...refs/tags/v0.10.6

Previous behaviour (<= 0.10.5)

Module Source:

source = "[email protected]:org/repo.git?ref=v1.1.1//terraform/"

.modules folder:
screen shot 2017-09-28 at 1 57 23 pm

Actual behaviour (>= 0.10.6)

Module Source:

source = "[email protected]:org/repo.git?ref=v1.1.1//terraform/"

.modules folder:

screen shot 2017-09-28 at 2 01 28 pm

Conclusion

Before 0.10.6 it was cloning the entire repo instead of just the folder where the terraform module source resides. This is particularly used when using relative folder references such as:

# -- VERSION
output "version"  { value = "${file("${path.module}/../VERSION")}" }

Thanks for reporting the issue!

This is a duplicate of #16138, already has a patch being tested in master.

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.

Was this page helpful?
0 / 5 - 0 ratings