Problem
After upgrading your Terraform code to version 0.13, applies are failing with variations of this error. Depending on the provider in use, the path listed at the end of the error 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 starting with registry.terraform.io/-/
are a special way Terraform marks legacy addresses where the true namespace is unknown. For providers that were automatically installed in Terraform 0.12, Terraform 0.13 can automatically determine the new addresses for these using a lookup table in the public Terraform Registry, but for in-house providers you will need to provide the appropriate mapping manually.
The terraform state replace-provider
subcommand allows re-assigning provider source addresses recorded in the Terraform state, and so we can use this command to tell Terraform how to reinterpret the “legacy” provider addresses as properly-namespaced providers that match with the provider source addresses in the configuration.
Solution
When using Terraform CLI with the default local backend, the error may be resolved by replacing the provider in the state using the below steps.
If the state file is stored in a backend other than local
, the backend must be configured before the appropriate commands may be run. If the state file is stored locally, this step may be skipped.
If needed, we provide a guide for configuring the backend. As a note, it is not necessary to have the Terraform configuration files from the workspace downloaded into the local directory when performing this task. Once the remote
backend is configured, the following steps will replace the providers in the state file.
- First, initialize Terraform.
$terraform init
- Once Terraform has been initialized, the following syntax may be used to replace the providers in the state file. You will be asked to confirm the change, which will only proceed if answered with “yes”.
$ terraform state replace-provider registry.terraform.io/-/aws registry.terraform.io/hashicorp/aws
Once the commands have been run, verify that a new version of the state is created by navigating to the workspace on Terraform Enterprise or Terraform Cloud UI, clicking on States and checking for the latest version created “seconds ago”.
For comprehensive guides on how to use CLI with Terraform Cloud or Terraform Enterprise, please visit our tutorials from HashiCorp Learn
Additional Information
Additional information regarding 0.13 upgrades can be read here:
https://www.terraform.io/upgrade-guides/0-13.html