Shared "Cache" of Terraform Providers #810
-
Greetings! I am trying to accomplish something, that I know must be possible and I am just missing it in the documentation. I am trying to make it so that I can have a shared cache of Terraform Providers that is used by ALL modules within my Terragrunt Project. I have over 475 modules (all AWS based), and it doesn't seem sane to me that I would need to download the AWS provider 475 times, when once should be all that is required. I have tried using the terragrunt-cache mechanism, but as noted I then have to limit parrallelism to 1. Is there a better way? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hey @dhoffman-vertex ! There is a long, in-depth discussion about this topic here. The TLDR is that you can use standard provider plugin caching, but you can experience errors when running multiple Terragrunt operations concurrently while using it, as Terraform has no locking mechanism that makes it safe to access from multiple concurrent sources. The simplest way to mitigate that drawback is to init with a parallelism of 1, then run the operation you want without limiting parallelism. That will populate the shared provider cache in a sequential fashion, then the plan, apply, etc can be run in parallel. |
Beta Was this translation helpful? Give feedback.
-
Note that we're also working on a better way to cache providers, even with |
Beta Was this translation helpful? Give feedback.
-
Thank you @yhakbar and @brikis98 While we wait for the ultimate solution in gruntwork-io/terragrunt#3001, I am posting the solution I ultimately came to given the information @yhakbar provided in hopes that if others come here looking for an answer, they will be able to leverage what I have learned over the last 24 hours.
I creates a simple providers.tf file
Then, by unsetting the value of the
NOTE: I found I had to limit the parallelism to 10 in my case, but I believe that to be more of the circumstances of my environment (ephemeral GitHub Action Runners in Kubernetes) than that of Terragrunt.
NOTE: I did note that there were many warnings when running the apply with the no-auto-init that it had detected a need to reinit and that further attempts could fail, but it seemed to work fine. Ultimately I opted to add a |
Beta Was this translation helpful? Give feedback.
Hey @dhoffman-vertex !
There is a long, in-depth discussion about this topic here.
The TLDR is that you can use standard provider plugin caching, but you can experience errors when running multiple Terragrunt operations concurrently while using it, as Terraform has no locking mechanism that makes it safe to access from multiple concurrent sources.
The simplest way to mitigate that drawback is to init with a parallelism of 1, then run the operation you want without limiting parallelism. That will populate the shared provider cache in a sequential fashion, then the plan, apply, etc can be run in parallel.