当我在苹果硅macbook pro上为我的谷歌云平台项目运行terraform init
时,我得到这个错误。
Provider registry.terraform.io/hashicorp/google v3.57.0 does not have a package available for your current platform, darwin_arm64.
我该如何解决这个问题?我以为Rosetta2模拟器会选中这个框,但是唉……
使用tfenv包从头构建Terraform,该包可以构建适合平台架构的特定版本。
我运行以下命令来安装在我的M1 Macbook(本例中是1.3.3版本)下运行的版本:
brew uninstall terraform
brew install tfenv
TFENV_ARCH=amd64 tfenv install 1.3.3
tfenv use 1.3.3
大多数提供商已经提供了新版本的软件包。您可以通过以下方式更新提供商:terraform init -upgrade
如果你不接受这种方法,或者它不能解决问题,请看下面的答案。
从头构建Terraform的GCP提供商!我修改了这个演练。https://github.com/hashicorp/terraform/issues/27257 issuecomment - 754777716
brew install --build-from-source terraform
这也将安装Golang(这篇文章似乎正在工作)
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
go fmt
make build
下面的目录可能不存在,所以让我们创建它并复制我们刚刚构建的二进制文件。
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安装的位置。如果您这样做,那么修改上面的命令以说明新构建二进制文件的位置。
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
感谢这个repo: https://github.com/kreuzwerker/m1-terraform-provider-helper。这将为我们省去构建和编译的开销。
用法:
brew install kreuzwerker/taps/m1-terraform-provider-helper
m1-terraform-provider-helper activate # (In case you have not activated the helper)
m1-terraform-provider-helper install hashicorp/template -v v2.2.0 # Install and compile
这将在位置为我们的arm_64编译提供程序:
~/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64
为了使其有效,以下是我的发现:-
- 你的Terraform版本应该至少是>=1.0.2
- 您应该从
.terraform.lock.hcl
中删除所请求的提供程序[模板]的旧校验和- 或试着运行
m1-terraform-provider-helper lockfile upgrade
,它会找到并更新这些校验和
- 或试着运行
- 请更改您需要在地形代码中安装的提供商和版本。
现在开始!!
OK。所以,我"找到"了问题的答案。你很可能和我一样,使用主键。
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "3.22.0"
}
}
}
provider "google" {
credentials = file("foo.json")
project = "foo"
region = "us-central1"
zone = "us-central1-c"
}
resource "google_compute_network" "vpc_network" {
name = "terraform-network"
}
好吧,把这部分删掉,你不需要了:
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "3.22.0"
}
}
}
如果它仍然不能工作,重新安装TERRAFORM并从一个新的干净的目录为您的项目启动。
希望这能帮助到一些人。
BTW,我的Terraform版本
起程拓殖v1.1.3
+ provider registry.terraform。io/hashicorp/谷歌v4.6.0
您可以通过以下命令列出支持的提供程序版本:
PROVIDER="hashicorp/google"
curl --silent https://registry.terraform.io/v1/providers/${PROVIDER}/versions | jq -r '.versions[] | select(.platforms[] | contains({os: "darwin", arch: "arm64"})) | .version'
然后在Terraform代码中使用required_providers
块中支持的一个版本。
这对我有用:
# Remove your local lock file!
rm .terraform.lock.hcl
# And then -
brew install kreuzwerker/taps/m1-terraform-provider-helper
m1-terraform-provider-helper activate
m1-terraform-provider-helper install hashicorp/template -v v2.2.0
terraform init