-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Labels
Description
Terraform Version
1.3.2Terraform Configuration Files
plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
Debug Output
no debug
Expected Behavior
Multiple terraform processes should work fine with the same plugin_cache_dir
Actual Behavior
Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using hashicorp/aws v4.34.0 from the shared cache directory
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using hashicorp/aws v4.34.0 from the shared cache directory
- Using hashicorp/aws v4.34.0 from the shared cache directory
- Using hashicorp/aws v4.34.0 from the shared cache directory
- Installing datadog/datadog v3.16.0...
╷
│ Error: Failed to install provider from shared cache
│
│ Error while importing hashicorp/aws v4.34.0 from the shared cache
│ directory: the provider cache at .terraform/providers has a copy of
│ registry.terraform.io/hashicorp/aws 4.34.0 that doesn't match any of the
│ checksums recorded in the dependency lock file.
Steps to Reproduce
I'm using terragrunt, which does initialization of multiple tf stacks at once.
Additional Context
Race condition between two terraform init happens when they are trying to install the same provider same version. First tf calls installFromHTTPURL and it downloads to a temporary file with random name, but then it calls installFromLocalArchive and this unpacks directly to global plugins cache directory - this is there race condition occurs.
- Targed dir set to
globalCacheDirhttps://github.com/hashicorp/terraform/blob/v1.3.2/internal/providercache/installer.go#L470 - Dir method
InstallPackageis called here https://github.com/hashicorp/terraform/blob/v1.3.2/internal/providercache/installer.go#L482 InstallPackagecallsinstallFromHTTPURLhere https://github.com/hashicorp/terraform/blob/v1.3.2/internal/providercache/dir_modify.go#L34installFromHTTPURLdownloads archive to temporary file, no possibility for race condition, good: https://github.com/hashicorp/terraform/blob/v1.3.2/internal/providercache/package_install.go#L56installFromHTTPURLcallsinstallFromLocalArchive: https://github.com/hashicorp/terraform/blob/v1.3.2/internal/providercache/package_install.go#L97installFromLocalArchivestarts decompressing directly to final path: https://github.com/hashicorp/terraform/blob/v1.3.2/internal/providercache/package_install.go#L128
So if another terraform init happens to see half-unpacked plugin in the middle of step 6 - it will use not ready file.
References
Houlistonm, joe-a-t, Sonam0110, tempus-prashannasimkhada, mkemp and 94 more