Problem
When running terraform apply or other commands after upgrading Terraform, you may encounter an error indicating that provider plugins are missing or corrupted. The error message references a provider version that is no longer required by your configuration.
Error: missing or corrupted provider plugins: │ - registry.terraform.io/hashicorp/aws: │ there is no package for │ registry.terraform.io/hashicorp/aws 5.29.0 cached in .terraform/providers
Cause
This error typically occurs when you upgrade from Terraform v1.0 or earlier to v1.1 or a later version. In versions prior to v1.1, the terraform init command did not automatically remove provider dependencies from the .terraform.lock.hcl file when they were no longer needed in the configuration.
After upgrading Terraform, subsequent commands may fail because the lock file contains stale entries for providers that are no longer used, causing Terraform to report them as missing.
Solution
To resolve this issue, you must regenerate the dependency lock file to remove the unneeded provider entries.
-
Run the
terraform initcommand with the-upgradeflag. This command re-evaluates the configuration and updates the lock file with only the currently required providers.$ terraform init -upgrade
After the command completes successfully, you can retry the operation that previously failed.
Additional Information
- For more details on the
initcommand, please refer to the Terraform CLIinitcommand documentation. - To learn more about how Terraform manages provider versions, see the Dependency Lock File documentation.