terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Dot files not copied when using module multiple times

Open seggcsont opened this issue 2 years ago • 2 comments

Terraform Version

0.15.5 or 1.1.4

Terraform Configuration Files

module "a" {
  source = "git::https://dev.azure.com/dummyorg/dummyproj/_git/terraform-generic-tools///.test?ref=test1"
}
module "b" {
  source = "git::https://dev.azure.com/dummyorg/dummyproj/_git/terraform-generic-tools///.test?ref=test1"
}
...

Debug Output

Expected Behavior

Module b source should be the same as module a.

Actual Behavior

Module b source has not dot files/directories

Steps to Reproduce

  1. Create a module with a dot file in it. Reference that file inside the module
  2. Use it at least twice in your tf file
  3. terraform init

Additional Context

It is an old bug. It was fixed that time. https://github.com/hashicorp/terraform/issues/22844

References

seggcsont avatar Mar 25 '22 08:03 seggcsont

Hi @seggcsont,

Thanks for filing the issue. The current installer is working as designed, as it was intended to skip any dotfiles when copying the source. The fact that the dotfiles appear in the first copy is an artifact that it is a direct git checkout, while each other instance is a copy of that source.

While the dot files are not intended to be included, so their existence cannot be counted on within the module, I think we do need to work out the details here to make sure this is always consistent one way or the other.

Thanks!

jbardin avatar Mar 25 '22 13:03 jbardin

Hi @jbardin and sorry about opening the duplicate, I definitely missed this issue in my search prior to opening a new one.

Regarding consistency, it's obvious that the behavior and content should be the same for fetched modules and copied ones, I agree.

However, regarding dot files specifically, it seems the reason they are left apart is to avoid copying a .git folder, which is a specific dot folder. How about changing the behavior to only leave aside the .git folder if any, as it's a special directory, and copy any other dot file seamlessly ?

In terraform context, there is nothing wrong with trying to read a file (with the file(...) function for example) named with a leading dot. This means that such files are perfectly OK to be in terraform modules, and should be treated equally.

NikolaLohinski avatar Aug 08 '22 07:08 NikolaLohinski

@jbardin

While the dot files are not intended to be included, so their existence cannot be counted on within the module, I think we do need to work out the details here to make sure this is always consistent one way or the other.

We currently use the information within the .git directory to automatically fetch remote url and commit id of a module. This breaks when using the same module more than once because the dot files are skipped when copying. Would you accept a PR that makes skipping of dot files a configurable setting?

Klaas- avatar Dec 13 '22 10:12 Klaas-

The current installer is working as designed, as it was intended to skip any dotfiles when copying the source.

I can't seem to find any reference to this constraint on the module's documentation. Did I miss it?

kallangerard avatar Oct 10 '23 05:10 kallangerard

Replicates #3185

It seems undocumented behaviour is the main issue.

kallangerard avatar Oct 10 '23 05:10 kallangerard