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

Inconsistent cache behavior for TF modules (symlinking and copying) #896

Closed
agrzegorczyk-leonsoftware opened this issue Oct 7, 2019 · 6 comments

Comments

@agrzegorczyk-leonsoftware

Terragrunt: 0.19.28
Terraform: 0.12.9

I observed some inconsistent cache behavior when I use multiple instances of the same terraform module (local modules with absolute paths).

For example, when I have definitions like this:

module "app-config_stable" {
  source = "/home/devops/terragrunt/tf-modules/app-config2s3"
  <some parameters>
}

module "app-config_rc" {
  source = "/home/devops/terragrunt/tf-modules/app-config2s3"
  <some parameters>
}

module "app-config_bgjobs" {
  source = "/home/devops/terragrunt/tf-modules/app-config2s3"
  <some parameters>
}

after terragrunt init

Initializing modules...
Downloading /home/devops/terragrunt/tf-modules/app-config2s3 for app-config_bgjobs...
- app-config_bgjobs in .terraform/modules/app-config_bgjobs
Downloading /home/devops/terragrunt/tf-modules/app-config2s3 for app-config_rc...
- app-config_rc in .terraform/modules/app-config_rc
Downloading /home/devops/terragrunt/tf-modules/app-config2s3 for app-config_stable...
- app-config_stable in .terraform/modules/app-config_stable

my cache folder looks like that :

$ ls -l .terragrunt-cache/KEfyB7ITkLsPXqImO_Z92_U_A-g/fx0EFDFeTvQ9pVZgnTHLPg1JonE/.terraform/modules/ | grep 'config'
lrwxrwxrwx 1 geck geck   48 Oct  7 18:16 app-config_bgjobs -> /home/devops/terragrunt/tf-modules/app-config2s3
drwxrwxr-x 2 geck geck 4096 Oct  7 18:16 app-config_rc
drwxrwxr-x 2 geck geck 4096 Oct  7 18:16 app-config_stable

One instance of the module is symlinked and all others are copied. AFAIS this behavior is repeatable, always the same, and only one instance is symlinked. This applies to all other used TF modules.
Personally, I prefer symlinking over copying in that case, but more important is consisted behavior for all occurrences of the module because current situation produces hard-to-tracking side effects.

@lorengordon
Copy link
Contributor

I'm fairly certain this is a TF 0.12 feature, where it now detects whether multiple modules reference the same source and only downloads the source one time. Other module instances are symlinked to the downloaded copy (presuming the OS supports symlinks).

However, now I cannot find the reference for that feature... Was either in a GitHub issue or one of the TF 0.12 blog entries...

@lorengordon
Copy link
Contributor

Here it is: hashicorp/terraform#11435 (comment)

@agrzegorczyk-leonsoftware
Copy link
Author

@lorengordon
Thank you for comment, but this is exactly the opposite: one symlink to the source and many independent copies of it.

@yorinasub17
Copy link
Contributor

Do you get the exact same inconsistent behavior if you use terraform directly, without going through terragrunt?

@agrzegorczyk-leonsoftware
Copy link
Author

agrzegorczyk-leonsoftware commented Oct 8, 2019

@lorengordon
You probably are right about the root cause of this problem. This behavior can be a side effect of change you linked.
@yorinasub17
Actually, I do. In fact, this problem occurs on a terraform level, not terragrunt.

Thank you both for your tips, I will recreate this issue on terraform repo.

@agrzegorczyk-leonsoftware
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants