Fix legacy provider addresses in Terraform 0.13
Move your Terraform state from the old -/aws provider address to hashicorp/aws, without changing any infrastructure.
· Updated
Upgrading straight from Terraform 0.11.15 to 0.13.7 can leave your state pointing at providers under an old address, so terraform init and terraform plan fail. This guide moves the state to the new address without changing any of your infrastructure.
Symptoms
After the upgrade, you see one or more of these errors when you run terraform init, terraform plan or terraform apply:
Error: Invalid legacy provider addressProvider registry.terraform.io/-/aws could not be foundFailed to instantiate providerWhy it happens
Terraform 0.11 assumed official providers came from HashiCorp. A block like this:
provider "aws" {}was stored in state under the legacy address registry.terraform.io/-/aws.
Terraform 0.13 names each provider's source explicitly, in a required_providers block:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}so it looks for registry.terraform.io/hashicorp/aws. Your state still says -/aws, and Terraform can't find the provider until the state is updated. Only the provider's address is affected: there's no drift and nothing wrong with your infrastructure.
Before you start
- Terraform 0.13.x installed (
terraform version). - A backup of your working directory.
- A backup of your state:
terraform state pull > terraform.tfstate.backupWarning
Back up your state before any state command. replace-provider only changes metadata, but you should always be able to restore the state file.
Steps
Check the state for the legacy address. Run
terraform state pulland look forregistry.terraform.io/-/aws. If it's there, carry on.Update your configuration with the upgrade helper. It adds
required_providersand updates your provider blocks. It changes configuration files only, not state.terraform 0.13upgradeReplace the legacy address in your state. Terraform asks you to confirm. It changes only the provider reference and doesn't create, change or destroy any resources.
terraform state replace-provider \ registry.terraform.io/-/aws \ registry.terraform.io/hashicorp/awsReinitialise Terraform, so it downloads the provider from its new address.
terraform initRun a plan to check the upgrade worked.
terraform plan
What happens next
If terraform plan runs without provider address errors, the upgrade is done. Run terraform state pull again and the provider now shows as registry.terraform.io/hashicorp/aws:
| Before (0.11) | After (0.13) |
|---|---|
registry.terraform.io/-/aws | registry.terraform.io/hashicorp/aws |
You only need to do this once per state file.
Tip
When upgrading across several versions, go one version at a time, run terraform plan after each step, and commit the changes terraform 0.13upgrade makes before moving on.