carloscastro.io
~/posts $ cat terraform_legacy_provider.md
title

Terraform 0.14: Invalid legacy provider address

date
kind
postmortem
tags
Terraform
applies_to
Local and remote state.
broke
terraform init fails after upgrading straight to 0.14 from a version below 0.13.
why
The state still refers to the unqualified provider “aws”, because the 0.13 upgrade never ran.
changed
Rewrote the provider address in the state with terraform state replace-provider.

What broke

I upgraded to Terraform 0.14 directly from a version below 0.13. terraform init stopped with this error:

Error: Invalid legacy provider address

This configuration or its associated state refers to the unqualified provider
"aws".

You must complete the Terraform 0.13 upgrade process before upgrading to later
versions.

This example is for the aws provider.

Why

The state still refers to the unqualified provider “aws”. Terraform 0.14 expects the 0.13 upgrade to have run first, and stops until it has.

What I changed

Running the code once with Terraform 0.13 clears the error. When that isn’t an option, rewrite the provider address in the state:

terraform state replace-provider "registry.terraform.io/-/aws" "hashicorp/aws"

Terraform asks you to confirm the change. It works the same for local and remote state, for example with an S3 backend:

terraform {
    backend "s3" {
        bucket = "my-remote-state-bucket"
        key    = "my-remote-state-key"
        region = "eu-west-1"
        dynamodb_table = "my.terraform.lock" # for state lock
        encrypt = true
    }
}

Afterwards

Run terraform init again. It should now succeed.