Sam Debruyn

Cloud Data Solution Architect

Specialized in Microsoft Azure, Fabric & modern data stack. Microsoft Data Platform MVP. dbt Community Award. Public speaker & meetup organizer. OSS contributor.

Sam Debruyn

Setting up your machine for local Terraform provider development

2 minutes

If you’ve been developing Terraform providers, you might have upgraded your machine to use the newly released Terraform 0.13. This version introduces a lot of changes related to where providers can be found.

Before version 0.13 you would just put the binary of your provider in ~/.terraform.d/plugins and you could start using your provider. There is a lot more to it in Terraform 0.13 and newer.

First, create a folder on your filesystem where you want to store the providers you’re working on. This folder itself has to follow a very specific structure and naming convention . I chose to put everything inside a directory called terraform-providers in my home directory.

1mkdir -p ~/terraform-providers/local/providers/

Now create a subdirectory for each provider you’re working on. Include your OS and architecture (mine is macOS 64-bit). The version doesn’t really matter.

1mkdir -p ~/terraform-providers/local/providers/someprovider/1.0.0/darwin_amd64

This directory has to contain your binary provider like before. You can symlink your binary to this directory so that you don’t have to copy it after each compilation.

1ln -s ~/repos/terraform-provider-someprovider/terraform-provider-someprovider ~/terraform-providers/local/providers/someprovider/1.0.0/darwin_amd64/terraform-provider-someprovider

Next, we have to define this directory in a file called .terraformrc in your home directory. I used VS Code to edit it, but feel free to use any text editor you like.

1touch ~/.terraformrc
2code ~/.terraformrc

This is what we have to add in that file:

1provider_installation {
2  filesystem_mirror {
3    path    = "~/terraform-providers/"
4    include = ["local/providers/*"]
5  }
6  direct {
7    exclude = ["local/providers/*"]
8  }

This tells Terraform to not use the Terraform Registry for providers prefixed with local/providers, but use our local directory instead.

Now you can use the following configuration to point to your local copy:

 1terraform {
 2  required_providers {
 3    someprovider = {
 4      source  = "local/providers/someprovider"
 5      version = "1.0.0"
 6    }
 7    # add other providers here
 8  }
 9  required_version = ">= 0.13"

Initialize your project with terraform init to make sure the setup is working properly. If you experience any issues, you probably made a mistake in the folder structure and it’s worth looking into the documentation .

You might also like

If you liked this article, follow me on LinkedIn or other social media to stay up-to-date with my latest posts. You might also like the following 2 posts about related topics:

Debugging a Terraform provider

3 minutes

While contributing to a couple of Terraform providers I often found the need to set some breakpoints in the provider code and inspect what was going at runtime. However, debugging Terraform providers is not that easy apparently… I found a way to do this VS Code, but feel free to drop me a line if you have some other tips & tricks and I’ll update this post.