OCI Terraform Provider for Apple M1
UPDATE February 2022: Starting from the version v4.65.0
of OCI Terraform provider, it supports darwin_arm64
architecture officially. You will not need this workaround for the future versions.
If you are getting an incompatible provider version error in your Terraform development, it means that you recently switched to the new Apple M1 silicon.
Provider registry.terraform.io/hashicorp/oci v4.53.0 does not have a package available for your current platform, darwin_arm64.
OCI Terraform team still didn’t publish darwin-arm64 binaries, so you would need to build it on your own. It’s not too complex; follow the steps:
1.
Terraform is natively ready for Apple M1 silicons. Install it with brew (in my case latest version is v1.0.11):
# brew install terraform
# terraform -v
2.
You will need to have Go (it’s natively available for M1, in my case v1.17.3) since you will compile Terraform Provider for OCI to make it M1 native. Official docs recommend having Go v1.15.5, but the specified version is not natively supported on M1 silicons. We will use v1.17 instead:
# brew install go
# go version
3.
Since we use Go v1.17, we need to install goimports manually:
# go get golang.org/x/tools/cmd/goimports
4.
Export GOPATH variable and put bin to the path (optionally, can add it permanently to the .zshrc):
# export GOPATH=$HOME/go
# export PATH=$GOPATH/bin:$PATH
5.
Now, it’s time to clone Terraform Provider for OCI repository (https://github.com/terraform-providers/terraform-provider-oci) and check out the appropriate version (in my case v4.54.0):
# mkdir -p $GOPATH/src/github.com/terraform-providers
# cd $GOPATH/src/github.com/terraform-providers
# git clone https://github.com/terraform-providers/terraform-provider-oci.git
# cd terraform-provider-oci
# git checkout v4.54.0
6.
Everything is ready for building your Apple M1 silicon binary:
# make fmt
# make build
7.
Now, safely place the build executable in terraform environment by creating the folder and copying the binary inside:
# mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/oci/4.54.0/darwin_arm64/# cp $GOPATH/bin/terraform-provider-oci ~/.terraform.d/plugins/registry.terraform.io/hashicorp/oci/4.54.0/darwin_arm64
8.
You have just built and placed terraform-provider-oci (M1 native) in the right place. All you now need to do is to reference the freshly made OCI provider from your .tf script.
terraform {
required_providers {
oci = {
source = “hashicorp/oci”
}
}
}
Happy Terraforming:)