Problem
After upgrading your Terraform configuration to version 0.13, terraform apply commands fail with an error indicating a plugin reinitialization is required. The provider path in the error message may vary.
Initializing plugins and modules... Error: Could not load plugin Plugin reinitialization required. Please run "terraform init". Plugins are external binaries that Terraform uses to access and manipulate resources. The configuration provided requires plugins which can't be located, don't satisfy the version constraints, or are otherwise incompatible. Terraform automatically discovers provider requirements from your configuration, including providers used in child modules. To see the requirements and constraints, run "terraform providers". Failed to instantiate provider "registry.terraform.io/-/aws" to obtain schema: unknown provider "registry.terraform.io/-/aws"
Cause
Provider source addresses that begin with registry.terraform.io/-/ are legacy addresses from Terraform 0.12 and earlier where the provider's namespace was unknown. In Terraform 0.13 and later, providers require a full namespace (e.g., hashicorp/aws).
While Terraform 0.13 can automatically update addresses for official providers found in the public Terraform Registry, it cannot do so for in-house or other providers not in its lookup table. The terraform state replace-provider command is required to manually update the provider source addresses recorded in the Terraform state file to match the new, namespaced format.
Solution
This solution uses the terraform state replace-provider subcommand to update the provider addresses in your state file.
Prerequisites
If your state file is stored in a remote backend, such as HCP Terraform or Terraform Enterprise, you must configure the backend in your local environment before running the following commands. You do not need the full Terraform configuration for the workspace, only the backend configuration.
For guidance, refer to the article on configuring a remote backend for CLI operations.
If you are using a local state file, you can skip this step.
Procedure
-
Initialize the Terraform configuration directory to configure the backend and download plugins.
$ terraform init
-
Run the
terraform state replace-providercommand to map the legacy provider address to the new, namespaced address. This example uses the AWS provider.$ terraform state replace-provider registry.terraform.io/-/aws registry.terraform.io/hashicorp/aws
Terraform prompts for confirmation. You must type
yesto apply the change.
Outcome
After the command completes successfully, a new state version is created. You can verify this by navigating to your workspace in the Terraform Enterprise or HCP Terraform UI and checking the States tab for a new version created moments ago.
Additional Information
- For more details on upgrading, please review the official guide on Upgrading to Terraform v0.13.
- To learn more about using the CLI with HCP Terraform or Terraform Enterprise, refer to the tutorials on HashiCorp Learn.