Easiest way to use a local custom provider with Terraform 0.13

Hi, when developing a custom provider I often want to run terraform with a local built copy of my provider. With Terraform 0.12 this was possible by simply putting the provider in the same directory, with Terraform 0.13 this doesn’t work any more.

I’ve been trying to piece together the workflow from the documentation, but I can’t get it working. Terraform init either downloads the provider from the registry or complains it can’t find the provider.

The description of the new filesystem structure is really complicated: what path do I use if I don’t have a version?
My provider is kvrhdn/terraform-provider-honeycombio, should I place it under registry.terraform.io/kvrhdn/honeycombio/0.0.0/Darwin/terraform-provider-honeycombio?

My required_providers block looks like this:

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

Can someone describe the go-to-way to use a local binary with Terraform?

I’ve also tried setting ~/.terraform.rc with:

provider_installation {
  filesystem_mirror {
    path    = "~/.terraform.d/plugins"
    include = ["*honeycombio*"]
  }
}

But this didn’t seem to do anything.

Ideally I’d like to be able to specify a path in required_providers:

terraform {
  required_providers {
    honeycombio = {
      path = "./"
    }
  }
}

Just adding here. I am also having problems setting up a custom provider. Having a version number doesn’t solve this. In-house provider setup trouble

1 Like

Sorry that this is so awkward to get started with! Ideally there would be a much easier way to install providers locally, especially for testing and development. Something like a terraform providers install command would be welcome.

All providers must have a version. For local development, it might make sense to use the next version (e.g. 0.0.7), or a much higher version than you have released (e.g. 99.0.0).

Not quite: the OS/arch for a macOS system should be darwin_amd64, not Darwin. It’s also conventional to add the version number to the end of the binary, separated by underscore.

That is:

registry.terraform.io/kvrhdn/honeycombio/0.0.7/darwin_amd64/terraform-provider-honeycombio_v0.0.7

Thanks @alisdair. I’ve got it working now :slight_smile:

I’ve added the following to my Makefile:

version = 99.0.0
provider_path = registry.terraform.io/kvrhdn/honeycombio/$(version)/darwin_amd64/

install_macos:
	go build -o terraform-provider-honeycombio_$(version)

	mkdir -p ~/Library/Application\ Support/io.terraform/plugins/$(provider_path)
	cp terraform-provider-honeycombio_$(version)  ~/Library/Application\ Support/io.terraform/plugins/$(provider_path)

And when I run terraform init:

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!

Is there a cross-platform way to generate the darwin_amd64 part?

The platform is the Go OS and arch, joined with an underscore. I’m not aware of a fully robust way of generating it across all platforms, but for UNIX-like systems you could do something like go version | cut -d' ' -f4 | tr / _

1 Like

You can get the OS and Arch from go env, possibly like

echo "$(go env GOOS)_$(go env GOARCH)"
3 Likes