Build & install Terraform providers from source with Terraform 0.13
12 Oct 2020 · 3 min

With Terraform 0.13 it's now significantly easier to use community developed providers: include it in your configuration and Terraform will install the provider automatically from the Terraform Registry.

Unfortunately, this has also made it more difficult to use a provider that is not published on the registry. I found it surprisingly difficult to install a provider without using the registry, hence why I decided to document and share my steps.

In this blogpost I'll use my honeycomb.io Terraform provider (kvrhdn/honeycombio) as example, but the instructions should be similar for other providers.

1. Build the provider

To find out how to build your provider, resort to the documentation within its repository. A provider is distributed as binary and should be named in the following format:

terraform-provider-<name>_<version>

For example, v0.1.0 of the honeycombio provider is named:

terraform-provider-honeycombio_0.1.0

Most providers are written Go, in this case you can simply follow the following instructions. With Go installed, clone the repository and build an executable:

git clone https://github.com/kvrhdn/terraform-provider-honeycombio.git
cd terraform-provider-honeycombio
go build -o terraform-provider-honeycombio_99.0.0 .

This will build an executable that can be used by Terraform.

We use the version 99.0.0 to ensure the version of our custom-built provider is higher than any other existing version published on the Terraform registry.

2. Install the provider

The easiest way to install a provider with Terraform 0.13 is to place it in a local mirror directory. This directory differs per OS as documented here.

In the case of macOS this is ~/Library/Application Support/io.terraform/plugins.

Within the plugins directory, the providers are organized in a directory structure using the following format:

<registry>/<namespace>/<service>/<version>/<OS_arch>/

In the case of the honeycombio provider (on macOS) that would be:

registry.terraform.io/kvrhdn/honeycombio/99.0.0/darwin_amd64/

The OS/arch string can be retrieved using $(go env GOOS)_$(go env GOARCH):

# on macOS
 echo $(go env GOOS)_$(go env GOARCH)
darwin_amd64

So to sum this up, the commands to copy the provider in the right directory for macOS are:

mkdir -p ~/Library/Application\ Support/io.terraform/plugins/registry.terraform.iokvrhdn/honeycombio/99.0.0/darwin_amd64/
cp terraform-provider-honeycombio_99.0.0 ~/Library/Application\ Support/io.terraform/plugins/registry.terraform.io/kvrhdn/honeycombio/99.0.0/darwin_amd64/

3. Use it!

Declare the provider as usual in the terraform configuration block:

terraform {
    required_providers {
        honeycombio = {
            source = "kvrhdn/honeycombio"
        }
    }
}

And when running terraform init, you should something similar to:

Initializing the backend...

Initializing provider plugins...
- Finding latest version of kvrhdn/honeycombio...
- Installing kvrhdn/honeycombio v99.0.0...
- Installed kvrhdn/honeycombio v99.0.0 (unauthenticated)

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.

* kvrhdn/honeycombio: version = "~> 99.0.0"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Note the version of the installed provider: v99.0.0 (unauthenticated).


blog · about · home