-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Description
Context/use case
When operating in an environment with no external network access, I want to use a module accessed via the file system, but still leverage the versioning ability of a Git repository. In other words, I want to use a Terraform module which is inside a Git submodule on the filesystem. This works with an absolute path:
module "a" {
source = "git::/Users/myusername/repos/repository-name//sub-folder?ref=version-ref"
}but fails with a relative path (see below).
Terraform Version
$ terraform --version
Terraform v0.12.9Terraform Configuration Files
I'll give a distilled example.
Say I have a Git repository containing a piece of Terraform intended to be used as a module:
output "value" {
value = "some value"
}All it does is output some value.
I then have a repository which includes the above as a Git submodule.:
module "a" {
# Assume this path correctly traverses to where the Git submodule is located
source = "git::../terraform-repo/module-path//module-sub-directory"
}
output "a" {
value = module.a.value
}Expected Behavior
I expect terraform init to work with absolute or relative file paths.
Actual Behavior
The absolute file paths work, but relative paths always yields:
Error: Failed to download module
Could not download module "a" (main.tf:1) source code from
"git::../../../myusername/dev/test-terraform/test-modules": error downloading
'file:///myusername/dev/test-terraform/test-modules': /usr/bin/git exited with
128: Cloning into '.terraform/modules/a'...
fatal: '/myusername/dev/test-terraform/test-modules' does not appear to be a
git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Steps to Reproduce
Reference a Git repository using a local URL, such as "git::/Users/myusername/repos/repository-name//sub-folder?ref=version-ref", then change it to a relative URL.
Bonus fact
If you use a relative URL which goes up to the root directory it does work:
module "a" {
source = "git::../../../../Users/myusername/repos/repository-name//sub-folder?ref=version-ref"
}