애플 Silicon(M1)에서 Terraform 사용
release: https://releases.hashicorp.com/terraform/1.0.2/
changelog: https://github.com/hashicorp/terraform/blob/v1.0.2/CHANGELOG.md
기본적으로 공식 정보에 따르면 애플 실리콘(M1)에서 구 버전의 terraform과 terraform provider를 실행해야 한다면 이 글은 참고가 될 수 있다.
추기
04/08
terraform을 지원하는 애플 Silicon의 2진법은 아직 발표되지 않았지만,
hashicorp/terraform-provider-aws
와 hashicorp/terraform-provider-google
의 대응으로 자체적으로 구축할 필요가 없다.🎉hashicorp/terraform-provider-aws는 v3입니다.30.0 대응.
hashicorp/terraform-provider-google는 v3입니다.63.0으로 대응하다.
개시하다
개인이 지난해 12월 구매한 M1 맥북 프로를 사용하고 있다.
아직 공식 발표는 안 됐지만, 고와 도커가 모두 이동하고 있어 개인 개발에 어려움이 없을 것으로 보인다.
최근 Terraform을 사용할 때 설치한 것이기 때문에 (2021/1) 대응 방법을 소개합니다.
전제로 터미널은 Rosetta2를 사용하지 않고 Homebrew
/opt/homebrew
에 설치됩니다.Go1.16 베타1 공개, M1도 이동할 수 있습니다.
현재 M1 환경에서 Homebrew를 통해 go를 설치하면 go1입니다.16beta1을 설치합니다.
brew install go
Terraform 설치
Terraform
--build-from-source
option을 설치하여 소스에서 설치할 수 있습니다.terraform 0.147 이후 Homebrew가 애플 Silicon을 대상으로 하는 2진법이 배포되기 때문에 원본에서 구축할 필요가 없습니다.
brew install terraform
$ terraform version
Terraform v0.14.4
이렇게 하면terraform 자체가 이동하지만aws와 gcp의provider가 지원하지 않기 때문terraform init
실행에 실패했습니다.$ terraform init
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 3.22.0"...
Error: Incompatible provider version
Provider registry.terraform.io/hashicorp/aws v3.22.0 does not have a package
available for your current platform, darwin_arm64.
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.
Terraform Provider의 수동 설치
또한 원본에서 필요한provider를 구축하여plugensdirectory에 설정하면 이동할 수 있습니다.
terraform-provider-aws
소스에서 생성되어
~/.terraform.d/plugins
에 배치됩니다.필요에 따라 버전
3.22.0
을 변경하십시오.$ git clone [email protected]:hashicorp/terraform-provider-aws.git
$ cd terraform-provider-aws
$ git checkout v3.22.0
$ make build
$ mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/aws/3.22.0/darwin_arm64
$ cp $(which terraform-provider-aws) ~/.terraform.d/plugins/registry.terraform.io/hashicorp/aws/3.22.0/darwin_arm64/terraform-provider-aws_v3.22.0
이렇게terraform init
성공했어요.$ terraform init
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 3.22.0"...
- Installing hashicorp/aws v3.22.0...
- Installed hashicorp/aws v3.22.0 (unauthenticated)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
terraform-provider-google
이쪽도 마찬가지야.
$ git clone [email protected]:hashicorp/terraform-provider-google.git
$ cd terraform-provider-google
$ git checkout v3.51.0
$ make build
$ mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/google/3.51.0/darwin_arm64
$ cp $(which terraform-provider-google) ~/.terraform.d/plugins/registry.terraform.io/hashicorp/google/3.51.0/darwin_arm64/terraform-provider-google_v3.51.0
문제 해결
Terraform Cloud 사용 중 오류 발생
Execution Mode: Remote에서 Terraform Cloud를 사용하면 다음과 같은 오류
terraform plan
가 실패합니다.Error: Failed to install provider
Error while installing hashicorp/google v3.51.0: the current package for
registry.terraform.io/hashicorp/google 3.51.0 doesn't match any of the
checksums previously recorded in the dependency lock file
오류 메시지와 같이 .terraform/.terraform.lock.hcl
에 기재된 checksum와 일치하지 않아provider의 설치가 실패했습니다.이때 삭제
.terraform/.terraform.lock.hcl
를 통해 제거됩니다.Homebrew 설치를 사용하는 중 오류 발생
다음 오류가 발생하면 Rosetta2를 사용하여 터미널을 시작할 수 있습니다.
예를 들어 Rosetta2에서 VScode를 시작할 때 Integrated Terminal에서 Homebrew를 사용하여 설치를 수행할 수 없습니다.
Error: Cannot install in Homebrew under Rosetta 2 in ARM default prefix (/opt/homebrew)!
tfenv 사용 시
terraform 1.0.1 이하 버전에서는 공식적으로arm64에binary를 나누어 주지 않았기 때문에
tfenv install 1.0.1
처럼 실행하면 실패할 수 있습니다.tfenv에서terraform의 원본 코드로 구축할 수 없습니다.terraform 1.0.1 이하 버전을 사용하려면amd64를 가리키는binary를 설치하고Rosetta2에서 실행해야 합니다.
TFENV_ARCH=amd64 tfenv install 1.0.1
참조: https://github.com/tfutils/tfenv#tfenv_arch이렇게 하면terraform 1.0.1 이하의amd64에 사용되는binary가 설치되어 있습니다.
Reference
이 문제에 관하여(애플 Silicon(M1)에서 Terraform 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/ww24/articles/e52e7a9f3332b4텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)