Solved: Local provider discovery failing with 0.13

I’ve followed the 0.13 upgrade guide but I seem to be hitting some issues with local provider discovery.

The plugin exists in a dir on the plugin lookup paths:

$ ls /home/shw/.terraform.d/plugins/mycorp.io/mycorp/gotemplate/1.0.0/linux_amd64/
terraform-provider-gotemplate_v1.0.0

And it is configured correctly in versions.tf:

terraform {
  required_providers {
    gotemplate = {
      source  = "mycorp.io/mycorp/gotemplate"
      version = "1.0.0"
    }
  }
  required_version = ">= 0.13"
}

However, when I try and init the root module, I can see from the trace logs that Terraform finds my provider, but then attempts to find it on registry.terraform.io, even though it is configured correctly with an FQDN in my config.

terraform init will fail with the following:

Error: Failed to query available provider packages

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

These are the relevant lines from the trace output log:

2020/08/24 16:31:28 [TRACE] getproviders.SearchLocalDirectory: found mycorp.io/mycorp/gotemplate v1.0.0 for linux_amd64 at /home/shw/.terraform.d/plugins/mycorp.io/mycorp/gotemplate/1.0.0/linux_amd64
2020/08/24 16:31:29 [TRACE] getproviders.SearchLocalDirectory: found mycorp.io/mycorp/gotemplate v1.0.0 for linux_amd64 at .terraform/plugins/mycorp.io/mycorp/gotemplate/1.0.0/linux_amd64
2020/08/24 16:31:29 [TRACE] providercache.fillMetaCache: including .terraform/plugins/mycorp.io/mycorp/gotemplate/1.0.0/linux_amd64 as a candidate package for mycorp.io/mycorp/gotemplate 1.0.0
2020/08/24 16:31:33 [TRACE] getproviders.SearchLocalDirectory: found mycorp.io/mycorp/gotemplate v1.0.0 for linux_amd64 at .terraform/plugins/mycorp.io/mycorp/gotemplate/1.0.0/linux_amd64
2020/08/24 16:31:33 [TRACE] providercache.fillMetaCache: including .terraform/plugins/mycorp.io/mycorp/gotemplate/1.0.0/linux_amd64 as a candidate package for mycorp.io/mycorp/gotemplate 1.0.0
2020/08/24 16:31:33 [DEBUG] GET https://registry.terraform.io/v1/providers/-/gotemplate/versions
2020/08/24 16:31:33 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/-/gotemplate/versions

Can anyone enlighten me as to what is going on here? Where does this mysterious -/gotemplate provider come from?

Hi @glitchcrab,

This special -/gotemplate address syntax is a special syntax used to mark an existing reference, not yet qualified with a namespace, in your previous state snapshot. There’s a little more background on that in the In-house Providers section of the upgrade guide.

You can tell Terraform explicitly which qualified provider you intend to use as your gotemplate provider moving forward using the terraform state replace-provider command:

terraform state replace-provider 'registry.terraform.io/-/gotemplate' 'mycorp.io/mycorp/gotemplate'

This command will retrieve the state snapshot from your most recent Terraform operation, replace all of the unqualified references to the “gotemplate” provider with references to mycorp.io/mycorp/gotemplate, and then push the updated state as a new snapshot to your configured backend.

After that, you can run terraform providers to see what Terraform has detected as the required providers for your configuration. If the above was successful then there should no longer be any references to -/gotemplate, because both your configuration and your state snapshot will refer to the qualified address mycorp.io/mycorp/gotemplate.

1 Like

Right, that makes perfect sense - thanks for clearing that up @apparentlymart :slight_smile: