本文介绍了如何让 `terraform init` 在我的 Apple Silicon Macbook Pro 上为 Google Provider 运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Apple Silicon macbook pro 上为我的 Google Cloud Platform 项目运行 terraform init 时,出现此错误.

When I run terraform init for my Google Cloud Platform project on my Apple Silicon macbook pro I get this error.

Provider registry.terraform.io/hashicorp/google v3.57.0 does not have a package available for your current platform, darwin_arm64.

我该如何解决这个问题?我以为 Rosetta2 模拟器会选中此框,但唉...

How can I work around this? I thought that the Rosetta2 emulator would check this box, but alas...

推荐答案

大多数提供商已经提供了更新版本的软件包.您可以通过以下方式更新提供程序:terraform init -upgrade如果这条路线不适合您或无法解决问题,请查看下面的答案.

Most providers already have packages available in newer versions.You can update the provider via:terraform init -upgradeIf this route is not acceptable for you or if it does not solve the problem, look at the answer below.

从头开始构建 Terraform 的 GCP 提供程序!我修改了这个演练.https://github.com/hashicorp/terraform/issues/27257#issuecomment-754777716

Build Terraform's GCP provider from scratch! I modified this walkthrough. https://github.com/hashicorp/terraform/issues/27257#issuecomment-754777716

brew install --build-from-source terraform

这也将安装 Golang(并且在这篇文章中似乎可以正常工作)

This will install Golang as well (and that appears to be working as of this post)

git clone https://github.com/hashicorp/terraform-provider-google.git
cd terraform-provider-google
git checkout v3.22.0
go get -d github.com/pavius/impi/cmd/impi
make tools
make build

以下目录可能不存在,所以让我们创建它并复制我们刚刚构建的二进制文件.

The following directory probably does not already exist so lets create it and copy the binary we just built.

mkdir -p ${HOME}/.terraform.d/plugins/registry.terraform.io/hashicorp/google/3.22.0/darwin_arm64
cp ${HOME}/go/bin/terraform-provider-google ${HOME}/.terraform.d/plugins/registry.terraform.io/hashicorp/google/3.22.0/darwin_arm64

请注意,如果您尚未定义 ${GOPATH},则 ${HOME}/go 是您的 golang 安装所在的位置.如果您这样做,请修改上述命令以说明新构建二进制文件的位置.

Note that ${HOME}/go is where your golang install will be located if you don't already have ${GOPATH} already defined. If you do, then modify the above commands to account for the location of your new build binaries.

cp ${GOPATH}/bin/terraform-provider-google ${HOME}/.terraform.d/plugins/registry.terraform.io/hashicorp/google/3.22.0/darwin_arm64

回到我的项目后瞧!

➜ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/google...
- Installing hashicorp/google v3.22.0...
- Installed hashicorp/google 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

这篇关于如何让 `terraform init` 在我的 Apple Silicon Macbook Pro 上为 Google Provider 运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 21:03