Tech Talk

Testing Terraform Providers Locally

Testing Terraform Providers Locally
  • Christoph Thale

  • 5 min

  • December 17, 2024

Want to contribute to a Terraform provider before publishing? Learn how to build, configure, and test a local provider binary – using the azurerm provider as a real-world example.

Develop and Test Terraform Providers Without Publishing Them

Terraform is one of the most popular Infrastructure-as-Code tools. When contributing a new feature to a provider like azurerm, you need a way to test locally. Here's how.

Prerequisites

  • Go installed (the provider is compiled in Go)
  • Terraform installed
  • Basic knowledge of Go and Terraform
  • macOS, Windows, or Linux

Build the Provider Binary

Navigate to the provider repository root (where main.go is located) and run:


GOOS=darwin GOARCH=arm64 go build

Adjust GOOS/GOARCH for your platform (darwin/windows/linux, arm64/amd64). The binary will be named terraform-provider-azurerm and will appear in the current directory.

Configure the Terraform CLI

Create or edit ~/.terraformrc (macOS/Linux) or %APPDATA%\terraform.rc (Windows):


provider_installation {   dev_overrides {     "registry.terraform.io/hashicorp/azurerm" = "/Users/you/go/bin"   }   direct {} }

provider_installation {   dev_overrides {     "registry.terraform.io/hashicorp/azurerm" = "/Users/you/go/bin"   }   direct {} }

Terraform will now use your local binary instead of the registry version.

Common Errors

  • exec format error – wrong architecture in go build command
  • Provider not found – misconfigured dev_overrides path

Always check the official developer and contribution guides before submitting a pull request.