M1 바이너리가 제공되지 않는 테라폼 프로바이더 빌드해서 쓰기 (hashicorp/template)


terraform init
실패한다.테라폼을 m1 맥북으로 사용할 때 가끔, arm64 다윈 커널용 바이너리가 없어서 terraform init
에 실패하는 경우가 있다. 내가 최근에 겪은 hashicorp/template
의 경우로 해결하는 짧은 경험을 공유하고자 한다.
What is the "Provider"?
Home - Plugin Development - Terraform by HashiCorp
Learn about developing plugins that connect Terraform to external services.

공식 문서에도 나와있듯, 테라폼의 플러그인이라고 이해하면 된다. 신기한건, Go 로 작성된 binary 라고 명세가 되어있다. 테라폼 Core 의 RPC 인터페이스와 통신해야한다고 하니.
준비 사항 - golang
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
소스코드는 golang 으로 작성되어있으므로, M1용 go를 설치한다. go 1.16 버전부터 m1 을 지원한다. golang 1.16 이 올해 나왔는데, 아카이브되었더라도 빌드해줬으면 이런 삽질을..
빌드

이미 archived 된 프로바이더인데, 어쩔 수 없이 써야하는 경우가 있다. 저 아래에 "SOURCE CODE" 라고 깃헙 레포지토리 링크가 있는데, 이걸 클론받는다.
git clone https://github.com/hashicorp/terraform-provider-template

이후 폴더에 들어가 go build
만 입력해주면 잘 빌드가 된다. 잘 빌드된 바이너리 terraform-provider-template
가 확인된다. 이를 옮겨준다.
$ mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64
$ mv terraform-provider-template ~/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64/terraform-provider-template_v2.2.0_x5
그리고 실행권한을 준다. 그러면 terraform init
이 잘 될 것이다.
$ chmod +x ~/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64/terraform-provider-template_v2.2.0_x5
