1

I have .terraform/modules folder generated by terraform itself. It's where terraform keeps modules by default and I'm fine with that.

when running terraform init command and if .terraform folder is gone it will try to pull modules again I would like to avoid that step by saying to use pre-populated modules folder from different location - it's like building shared cache folder for terraform for our CI/CD pipelines, pull only if new version of a modules specified otherwise use cache.

NOTE: 
We don't run anything on Jenkins locally, every `Stage` in Jenkins uses Ephemeral Docker 
container agents to run all the `Steps` and to keep Jenkins clean,  
otherwise I would use local workspace cache for all that.

is there a way to do that?

Thank you

Arsen
  • 509
  • 2
  • 8
  • 20
  • You would do a bind volume mount for the Docker build agent inside Jenkins Pipeline and then also leverage the `-plugin-dir` flag for the providers and plugins. Shared module cache may cause issues in automation. More details possible if you add more information to the question. – Matthew Schuchard Mar 09 '20 at 19:13
  • You'd need a separate volume for every single directory of Terraform code as the modules will change each time. This is going to quickly become unmanageable. Besides, are you really saving anything with this? Module fetching should be very fast as it's just pulling a few kb of source code. Your provider binary fetching is likely to be significantly slower and that can be fixed by either using the `plugin-dir` as mentioned above or having the plugin binaries in the same directory as Terraform as described by https://stackoverflow.com/a/50944611/2291321 – ydaetskcoR Mar 09 '20 at 19:24
  • @ydaetskcoR Yeah our terraform-modules are stored in github with different tags. and since last week getting modules from github is taking about 40-50 minutes and until it gets fixed I need to find work around – Arsen Mar 09 '20 at 19:43
  • How is it possibly taking 40-50 minutes to pull a few kb of source code? When you say "since last week" what changed? – ydaetskcoR Mar 09 '20 at 19:46
  • @ydaetskcoR Nothing has changed we don't know why is taking that long. – Arsen Mar 09 '20 at 19:50
  • Resolving Deltas taking that long – Arsen Mar 09 '20 at 19:50
  • We had this problem when the git port wasn't open in our build agent sg so it was having to timeout on each git pull before it fell back to 443. 9418 I think. – EJC Sep 27 '22 at 15:33

0 Answers0