J

Terraform provider development overrides

11 Apr 2021

If you’re working on a Terraform provider, chances are at some point you want to run in against your configuration before pushing the changes publicly. Until recently, this involved sketchy and error prones solutions such as (ab)using the filesystem mirror directives or modifying your $PATH. These approaches were tedious and in some cases resulted in more debugging that what the code change involved.

Good news is that Terraform 0.14 has addressed this using development overrides for provider developers. The design feature is designed in such a way that you don’t need to fiddle with the filesystem and instead you toggle it using an environment variable.

Setting it up

Inside of our configuration file, we use HCL to define our provider override. Below you can see I’m overriding cloudflare/cloudflare which is the provider I’m working on. The provider name is keyed to the file path where the compiled binary is outputted; in my case, inside of my $GOPATH.

provider_installation {
  dev_overrides {
    "cloudflare/cloudflare" = "/Users/jacob/go/src/github.com/cloudflare/terraform-provider-cloudflare"
  }

  direct {}
}

Don’t forget to include direct {} at the bottom to allow other providers to be pulled in as normal. Without this, you will only be able to use those providers defined in the dev_overrides block.

I put this file at ~/.config/terraform/devrc for reference.

Now that we have that file in place, all we need to do is invoke our Terraform operations prefixed with TF_CLI_CONFIG_FILE=~/.config/terraform/devrc and boom! Terraform is using your development provider instead of the released version.