Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 772
David Bruce Borenstein Avatar asked May 04 '20 20:05

David Bruce Borenstein


People also ask

How does terraform find and install providers?

Terraform CLI finds and installs providers when initializing a working directory. It can automatically download providers from a Terraform registry, or load them from a local mirror or cache. If you are using a persistent working directory, you must reinitialize whenever you change a configuration's providers.

What is the terraform registry?

The Terraform Registry is the main directory of publicly available Terraform providers, and hosts providers for most major infrastructure platforms. Each provider has its own documentation, describing its resource types and their arguments.

When does terraform report an error in a configuration?

When Terraform encounters an error in your configuration, it will report an error including line numbers and the type of issue found in the configuration. In this tutorial, you will clone a repository with a broken Terraform configuration to deploy an EC2 instance and underlying networking.

How do I use terraform validate with HCl?

terraform fmt only parses your HCL for interpolation errors or malformed resource definitions, which is why you should use terraform validate after formatting your configuration to check your configuration in the context of the providers' expectations. Initialize your Terraform directory to download the providers that your configuration requires.


2 Answers

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. :-)

like image 122
David Bruce Borenstein Avatar answered Oct 06 '22 14:10

David Bruce Borenstein


For Windows Users on Corporate Firewall, where direct download of provider zip file is not permitted.

  1. Simply download provider ZIP file by visiting corresponding URL.
  • Parent-URL: https://releases.hashicorp.com/
  • AWS-URL: https://releases.hashicorp.com/terraform-provider-aws/3.37.0/

  • Now, in the root directory - main.tf file which contains providers section.
  1. Create folder structure like registry.terraform.io\hashicorp\aws\3.37.0\windows_amd64 and place extracted exe file from above zip in this location.
  2. Go to the command line and run:

terraform init -plugin-dir .


Directory structure:

  • main.tf
  • registry.terraform.io\hashicorp\aws\3.37.0\windows_amd64\terraform_provider_aws_v3.37.0_x5.exe

aws_v3.37.0_x5.exe Directory Structure Snip

like image 33
rkdove96 Avatar answered Oct 06 '22 15:10

rkdove96