Search code examples
terraformrancherrke

Why doesn't Terraform see my manually installed provider?


I'm trying to install the RKE provider as part of the Rancher AWS quickstart. The Terraform documentation says that plugins should be installed at ~/.terraform.d/plugins. The RKE documentation says that the plugin should be installed at ~/terraform.d/plugins/<your_platform>.

Trying to reconcile the conflicting information, I tried copying the binary to all of the following locations, but Terraform never saw any of them:

~/.terraform.d/plugins/terraform-provider-rke
~/.terraform.d/plugins/rke
~/.terraform.d/plugins/darwin_amd64/terraform-provider-rke
~/.terraform.d/plugins/darwin_amd64/rke
~/terraform.d/plugins/terraform-provider-rke
~/terraform.d/plugins/rke
~/terraform.d/plugins/darwin_amd64/terraform-provider-rke
~/terraform.d/plugins/darwin_amd64/rke

In each case, when I ran terraform init, I got the following error:

Provider "rke" not available for installation.

A provider named "rke" could not be found in the Terraform Registry.

This may result from mistyping the provider name, or the given provider may
be a third-party provider that cannot be installed automatically.

In the latter case, the plugin must be installed manually by locating and
downloading a suitable distribution package and placing the plugin's executable
file in the following directory:
    terraform.d/plugins/darwin_amd64

Terraform detects necessary plugins by inspecting the configuration and state.
To view the provider versions requested by each module, run
"terraform providers".


Error: no provider exists with the given name

As a last resort, I could use terraform init -plugin-dir=<something>. But then Terraform doesn't see any of the automatically downloaded plugins, and I have to manually install everything.

Is there some path variable that's missing, or some other naming convention that I am failing to follow?


Solution

  • It turns out that the error message didn't tell the whole story. Terraform was finding the provider, but it didn't think it was a new enough version.

    According to Terraform's documentation, the provider needs to be named as terraform-provider-<NAME>_vX.Y.Z. The documentation for the RKE provider said that the file should be called terraform-provider-rke (no version number).

    In a comment in the Terraform source code for plugin discovery, it says that this versionless format is supported for reverse compatibility. However, Terraform interprets the version to be v0.0.0.

    When I ran terraform plan after the failed terraform init, it gave me a more informative error message:

    Error: provider.rke: no suitable version installed
      version requirements: "0.14.1"
      versions installed: "0.0.0"
    

    That version is presumably a requirement from another provider that depends on the RKE provider.

    I went back and manually downloaded that exact version from the Github repo and copied it into the plugins directory with the name terraform-provider-rke_v0.14.1. It worked!

    So there you go. When in doubt, look at the source code. Now to submit an issue report to Rancher, telling them to update their documentation. :-)