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:

text
Error: Invalid legacy provider address
text
Provider registry.terraform.io/-/aws could not be found
text
Failed to instantiate provider

Why it happens

Terraform 0.11 assumed official providers came from HashiCorp. A block like this:

hcl
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:

hcl
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:
bash
terraform state pull > terraform.tfstate.backup

Warning

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

  1. Check the state for the legacy address. Run terraform state pull and look for registry.terraform.io/-/aws. If it's there, carry on.

  2. Update your configuration with the upgrade helper. It adds required_providers and updates your provider blocks. It changes configuration files only, not state.

    bash
    terraform 0.13upgrade
  3. Replace 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.

    bash
    terraform state replace-provider \
      registry.terraform.io/-/aws \
      registry.terraform.io/hashicorp/aws
  4. Reinitialise Terraform, so it downloads the provider from its new address.

    bash
    terraform init
  5. Run a plan to check the upgrade worked.

    bash
    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/-/awsregistry.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.

Next steps