How to install third-party plugins in Terraform

Hashicorp already distributes plugins that it maintains along with the community (check them here), for instance, aws. That’s great, but soon enough you’ll need to use some provider that does not work out of the box by running terraform init.

In this post I will be showing you the quickest way of installing external plugins in terraform, without the need to dig deep into Terraform’s docs. We will be installing the phillbaker / terraform-provider-elasticsearch as an example.

Terraform plugins directory

Whenever you installed terraform, a ~/.terraform.d/ directory was created. To allow the use of external plugins we will need to create the plugins directory. Run the following command.

mkdir -p ~/.terraform.d/plugins/linux_amd64

Right now, I’m running Terraform on a linux machine, therefore the need for the linux_amd64 directory. If you are running a different operating system architecture please use the documentation to find the right one for you.

Downloading the binary

Most providers will expose their software packages via github releases, so that’s the place to look for the right binary for your architecture. For our example, this is the place.

curl -sL https://github.com/phillbaker/terraform-provider-elasticsearch/releases/download/v1.0.0/terraform-provider-elasticsearch_v1.0.0_linux_amd64 --output ~/.terraform.d/plugins/linux_amd64/terraform-provider-elasticsearch_v1.0.0

Notice that we are outputting the binary to the ~/.terraform.d/plugins/linux_amd64/ directory. Also, we are naming the binary with the terraform-provider-<NAME>_vX.Y.Z format. This is really important since it associates the version = "X.Y.Z" in the terraform provider code with the actual binary (It’s possible to have multiple versions of the same binary in your plugins folder).

Finally don’t forget to set the binary file as executable.

chmod +x ~/.terraform.d/plugins/linux_amd64/terraform-provider-elasticsearch_v1.0.0

That’s all there is to it. Now you can use the provider like you always do.

provider "elasticsearch" {
    version = "1.0.0"
 }

Run terraform init, and then you can run terraform version to make sure that the installation has been successful.

Terraform v0.12.18
+ provider.elasticsearch v1.0.0

Hope this helps!

References

· terraform