Abhishek's Blog

Abhishek's Blog

[Solved] Incompatible Terraform Provider Version - Apple Silicon (M1)

Problem

Working with terraform for managing infrastrucure is fun unless you are on Apple Silicon.

Many of terraform providers (non-official?) are yet to publish a version for Apple Silicon(darwin_arm64).

Running terraform init raises an error for Incompatible provider version

Provider registry.terraform.io/xxxxx/xxxxx vX.X.X does not have a
package available for your current platform, darwin_arm64.

Solution

We need to build plugin from source using go 1.16 and override terraform CLI config to lookup for provider locally than from registry.

For sake of example, let's us integrations/github provider.

  1. Check your golang version using go version, should be greater than 1.16 as golang added support for Apple Silcion in version 1.16.
  2. Clone source code of provider under GOPATH e.g. $GOPATH/src/github.com/integrations/terraform-provider-github
  3. Build and generate binary using go build -o /path/to/output/binary

Once we have darwin_arm64 compatible version of provider, we need to help terraform find this version locally.

Terraform provides a CLI configuration(Provider Installation) for cases where your machine cannot access public terraform registry due to firewall or in case you are developing your custom terraform provider to be fetched locally.

We need to add provider_installation block inside terraform cli configuration file e.g ~/.terraformrc or ~/terraform.rc

provider_installation {
    dev_overrides {
        "integrations/github" = "/path/to/output/binary"
    }
    direct {}
}

That's all, running terraform plan/apply will use local version of provider.

P.S. Please checkout my repo which creates a dev server on DigitalOcean, updates it's IP on Cloudflare DNS and adds SSH key on github using terraform.

P.P.S I'm new to terraform, any feedback on this post or repo will be highly appreciated. TIA.

Fin.

#terraform#go
 
Share this