How to I make terraform use a provider binary that I have on disk?

I have built a provider binary, and would like Terraform to use it rather than trying to download and install from registry. How do I do that?

Here’s the scenario:

  • terraform-provider-snowflake doesn’t include a freebsd build, so terraform init fails (PR to include freebsd)
  • it builds on FreeBSD, so I built it, and have tried to get terraform to use it. No luck so far. I did manage to get it working as a developer override, which is apparently not what I’m supposed to do.

So, I have a binary that I know works. I just need Terraform to use it.

$ terraform version
Terraform v1.4.6
on freebsd_amd64

$ find ~/.terraform.d/plugins -type f -name '*snowflake*'
/home/patmaddox/.terraform.d/plugins/registry.terraform.io/snowflake-labs/snowflake/0.6.4/freebsd_amd64/terraform-provider-snowflake_v0.64.0

$ cat main.tf
terraform {
  required_providers {
    snowflake = {
      source = "snowflake-labs/snowflake"
      version = "~> 0.64"
    }
  }
}

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding snowflake-labs/snowflake versions matching "~> 0.64"...
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider snowflake-labs/snowflake: no available releases match the given
│ constraints ~> 0.64

I have tried adding the following lines to ~/.terraformrc to make an explicit installation:

provider_installation {
  filesystem_mirror {
    path = "/home/patmaddox/.terraform.d/providers"
    include = ["snowflake-labs/snowflake"]
  }

  direct {}
}

which results in:

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding snowflake-labs/snowflake versions matching "~> 0.64"...
- Finding hashicorp/aws versions matching "~> 4.0"...
- Installing hashicorp/aws v4.67.0...
- Installed hashicorp/aws v4.67.0 (signed by HashiCorp)
╷
│ Error: Incompatible provider version
│ 
│ Provider registry.terraform.io/snowflake-labs/snowflake v0.64.0 does not have a package available for your current platform,
│ freebsd_amd64.
│ 
│ Provider releases are separate from Terraform CLI releases, so not all providers are available for all platforms. Other versions of
│ this provider may have different platforms supported.
╵

error: Recipe `terraform` failed on line 9 with exit code 1

Well, that was a “fun” several hours.

The binary is 0.64.0 but I had placed it in a dir named 0.6.4.

Hi @patmaddox,

Assuming that /home/patmaddox is your home directory, renaming your providers directory to plugins as shown under Implied Local Mirror Directories and then removing your provider_installation block should cause Terraform to infer an implied provider installation block equivalent to:

provider_installation {
  filesystem_mirror {
    path = "/home/patmaddox/.terraform.d/plugins"
    include = ["snowflake-labs/snowflake"]
  }

  direct {
    exclude = ["snowflake-labs/snowflake"]
  }
}

The exclude argument in direct avoids Terraform also asking the remote registry for available versions for this provider. I think what happened in your error message here is that it asked the origin registry registry.terraform.io for version 0.64.0 because (as you said in the later message) there was not a 0.64.0 package in your mirror directory – there was only 0.6.4.

If you prefer to keep it explicit then you could copy the configuration I wrote above and change plugins back to providers to match yours, and then it should give the same effect of only looking locally for this particular provider, while still asking the origin registry for every other provider. If you have an explicit provider_installation block then that totally disables Terraform’s Implied Local Mirror behavior.

Cool, I did that, and all is working. Thanks!

I don’t love that I spent so much time on this… but in the end I’m glad to know it was just bone-headedness on my part and that everything works smoothly as it should (and what I’ve come to expect from all things hashicorp).