Terraform 0.13 `terraform init` fails because of provider required by state

Having a problem with terraform init because of a provider required by state.

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Using previously-installed deviavir/gsuite v0.1.54
- Using previously-installed hashicorp/google v3.35.0
- Finding latest version of -/gsuite...

Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider -/gsuite:
provider registry registry.terraform.io does not have a provider named
registry.terraform.io/-/gsuite
$ terraform providers

Providers required by configuration:
.
├── provider[registry.terraform.io/deviavir/gsuite]
└── provider[registry.terraform.io/hashicorp/google]

Providers required by state:

    provider[registry.terraform.io/-/gsuite]

Can’t update state with an apply because init won’t work.

From the 0.13 upgrade guide:

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.

Warning: The terraform state replace-provider subcommand, like all of the terraform state subcommands, will create a new state snapshot and write it to the configured backend. After the command succeeds the latest state snapshot will use syntax that Terraform v0.12 cannot understand, so you should perform this step only when you are ready to permanently upgrade to Terraform v0.13.

terraform state replace-provider \
  'registry.terraform.io/-/happycloud' \
  'terraform.example.com/awesomecorp/happycloud'

The command above asks Terraform to update any resource instance in the state that belongs to a legacy (non-namespaced) provider called “happycloud” to instead belong to the fully-qualified source address terraform.example.com/awesomecorp/happycloud .

So for your use-case, this command should help:

terraform state replace-provider
  registry.terraform.io/-/gsuite
  registry.terraform.io/deviavir/gsuite

Hope this helps!

1 Like

Thank you! That was exactly what I needed. I completely scanned over that portion of the doc. :man_facepalming: