-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Issues with *-all commands and terraform plugin cache directory #1212
Comments
This is because terraform isn't really designed to handle multiple concurrent calls to the binary at once. This leads to issues when all the terraform processes are trying to initialize the plugin cache and download the same versions of the provider (overwrite each other). With that said, this should work as expected once the plugin directory is sufficiently seeded. Here are two other workarounds for this:
Solving this is something we've been thinking about, but we don't have any design for a solution right now. |
Terragrunt *-all commands run implicit Very strange that I had pipeline with |
If there is a way to implement Side note: I personally would rather invest in a proper dependency management solution. E.g., would be great if you could run |
As a quick and maybe quite clean workaround i followed another approach: i quickly wrote a bash wrapper script around terragrunt which basically does only the following:
Maybe as plan for implementation for the steps:
Does this seem realistic? I think this shouldn't be too hard and is quite clean. If yes, the number of needed downloads could be reduced drastically when having dozens of modules if one knows beforehand which plugins are needed. |
@Zyntogz your trick works because you have your terraform code locally. |
I worked around this by creating a cache-directory per plan. This does mean that each plan will have to download providers at least once, but on subsequent runs the cache can be used to fetch the providers. I configure my CI to cache the entire locals {
terraform_cache_dir = format("%s/%s", get_env("TF_PLUGIN_CACHE_DIR", "~/.terraform-plugin-cache"), path_relative_to_include())
}
terraform {
before_hook "provider_cache" {
commands = ["init", "validate", "plan", "apply"]
execute = ["mkdir", "-pv", local.terraform_cache_dir]
}
extra_arguments "provider_cache" {
commands = ["init", "validate", "plan", "apply"]
arguments = []
env_vars = {
TF_PLUGIN_CACHE_DIR = local.terraform_cache_dir
}
}
} |
We have some projects with many # In the general terragrunt.hcl configuration file.
terraform {
after_hook "after_delete_terragrunt_cache" {
commands = ["validate", "plan", "apply"]
execute = ["rm", "-rf", ".terragrunt-cache"]
working_dir = "${get_terragrunt_dir()}"
run_on_error = true
}
} Having a centralized |
@adamantike
|
So we've also encountered this issue when using Here is how we've fixed it : terraform {
source = "path/to/tf/module"
extra_arguments "terraform_args" {
commands = ["init"]
arguments = [
"-plugin-dir=/path/to/terraform/plugin-cache/"
]
}
} Hope it'll help you. |
@headincl0ud, you can either:
@Xat59, take into account that the approach of centralizing the plugin directory is susceptible to the issue explained in this comment. With parallelism set, and a project with many |
I am using terragrunt together with atlantis and terragrunt-config-generator and hit the same issue.
What confuses me, is the versions it looks up in the cache.
Is this a separate issue I am encountering here? |
I fixed something like this in #2542. Are you using Terragrunt >=v0.45.12? |
I was on v0.44.5. Upgrading to v0.45.18 fixed the issue. Thank you very much! |
@geekofalltrades I'm still seeing this with Terragrunt Seeding the plugin cache does not seem to help either, I'm running into this issue after running a
I can not find any way to use the plugin cache without terragrunt breaking completely so I guess I'll just have to commit to keeping tens of GB with copies of the same provider library. |
|
Hi @geekofalltrades, Terragrunt itself does not install providers, Terraform is responsible for that, and as stated in their official documentation, they do not guarantee safe operation if init happens in parallel.
Thus, we cannot influence it in any way. |
Resolved in v0.50.11 release. |
I am still seeing this issue with 0.50.11 |
Hi @Fomiller, The reason may be that Terragrunt does not correctly detect that the cache is used terragrunt/terraform/config.go Lines 10 to 18 in eec362e
Since Terragrunt detects correctly in my test environment, please provide an example to reproduce the issue. |
With the following When running
my providers declared in my root terragrunt.hcl file look like
The overall file directory structure is very similar to the original issues. |
Thank you @Fomiller! I will try to reproduce the issue locally and get back to you. |
@Fomiller, I'm sorry to be late with the reply. The only way at the moment is to run two commands:
We are working on the better solution #2920 |
Resolved in v0.56.4 release. Make sure to read Provider Caching. |
If I set
TF_PLUGIN_CACHE_DIR
to any directory and use any terragrunt*-all
commands fail withCould not satisfy plugin requirements
errors. My repro case bellow:terragrunt.hcl:
a/terragrunt.hcl:
example-tf-module/main.tf
then I create directories
b
throughm
and copya/terragrunt.hcl
to them. My final directory tree is:If cd to any of the one letter directories
terragrunt validate
works fine. From the root dir, with bothTF_LOG
andTG_LOG
set to debug,terragrunt validate-all
will fail some of the modules. TF/TG log and TF/TG putput from failed modules:Using
--terragrunt-parallelism 1
fixes this but it makes my real code super slow to validate/plan/apply. My workaround is to emulateterragrunt init-all --terragrunt-parallelism 1
using bash toterragrunt init
each module sequentially.The text was updated successfully, but these errors were encountered: