简体   繁体   English

如何让 `terraform init` 在我的 Apple Silicon Macbook Pro 上为 Google Provider 运行?

[英]How can I get `terraform init` to run on my Apple Silicon Macbook Pro for the Google Provider?

When I run terraform init for my Google Cloud Platform project on my Apple Silicon macbook pro I get this error.当我在 Apple Silicon macbook pro 上为我的 Google Cloud Platform 项目运行terraform init时,出现此错误。

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

How can I work around this?我该如何解决这个问题? I thought that the Rosetta2 emulator would check this box, but alas...我以为 Rosetta2 模拟器会勾选这个框,但是唉......

Another way to build Terraform from scratch is to use the tfenv package, which can build a specific version adapted to the platform architecture.从头开始构建Terraform的另一种方法是使用tfenv package,它可以构建适应平台架构的特定版本。

I ran the following to install a version that works under my M1 Macbook (version 1.3.3 in my case):我运行以下命令来安装适用于我的 M1 Macbook 的版本(在我的例子中是版本 1.3.3):

brew uninstall terraform
brew install tfenv
TFENV_ARCH=amd64 tfenv install 1.3.3
tfenv use 1.3.3

Most providers already have packages available in newer versions.大多数提供商已经提供了更新版本的软件包。 You can update the provider via: terraform init -upgrade If this route is not acceptable for you or if it does not solve the problem, look at the answer below.您可以通过以下方式更新提供程序: terraform init -upgrade如果您无法接受此路线或无法解决问题,请查看下面的答案。

Build Terraform's GCP provider from scratch.从头开始构建 Terraform 的 GCP 提供程序。 I modified this walkthrough.我修改了这个演练。 https://github.com/hashicorp/terraform/issues/27257#issuecomment-754777716 https://github.com/hashicorp/terraform/issues/27257#issuecomment-754777716

brew install --build-from-source terraform

This will install Golang as well (and that appears to be working as of this post)这也将安装 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
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

Note that ${HOME}/go is where your golang install will be located if you don't already have ${GOPATH} already defined.请注意,如果您尚未定义${GOPATH} ,则${HOME}/go是您的 golang 安装所在的位置。 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

After going back to my project voila!回到我的项目后瞧!

➜ 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

Thanks for this repo: https://github.com/kreuzwerker/m1-terraform-provider-helper .感谢这个 repo: https://github.com/kreuzwerker/m1-terraform-provider-helper This will remove the overhead of building and compiling from us.这将消除我们构建和编译的开销。

Usage :用法

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

This will compile the provider for our arm_64 in the location:这将在以下位置为我们的 arm_64 编译提供程序:

~/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64

For this to be working, these are my findings:-为了使它起作用,这些是我的发现:-

  • Your terraform version should be atleast >= 1.0.2您的 terraform 版本应该至少 >= 1.0.2
  • You should delete the older checksums of the requested provider [template in my case] from the .terraform.lock.hcl您应该从.terraform.lock.hcl中删除请求的提供者 [在我的例子中是模板] 的旧校验和
  • Please change your provider and version that you need to be installed in the terraform code.请在 terraform 代码中更改您需要安装的提供商和版本。

Go ahead now !!!现在提前Go !!!

Most providers already have packages available in newer versions.大多数提供商已经提供了更新版本的软件包。

You can update the provider via:您可以通过以下方式更新提供程序:

terraform init -upgrade

If this route is not acceptable for you or if it does not solve the problem, look at the answer of reka18.如果这条路线不适合你或者没有解决问题,请看reka18的回答。 And maybe create an issue in the repository of this provider to request this package so others can benefit from it in the future.并且可能在此提供程序的存储库中创建一个问题以请求此 package 以便其他人将来可以从中受益。

OK.好的。 So, I ''found'' the answer to my problem.所以,我“找到”了我的问题的答案。 You most probably, like me, use the main.tf config that look like this:您很可能像我一样使用如下所示的 main.tf 配置:

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"
}

Well, DROP this part, you do not need it:好吧,删除这部分,你不需要它:

terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
      version = "3.22.0"
    }
  }
}

If it still not working, reinstall TERRAFORM and start from a new fresh and clean directory for your project.如果仍然无法正常工作,请重新安装 TERRAFORM 并从新的干净目录开始为您的项目。

Hope this can help some one.希望这可以帮助一些人。

BTW, my Terraform version顺便说一句,我的 Terraform 版本

Terraform v1.1.3 Terraform v1.1.3
on darwin_arm64在 darwin_arm64 上
+ provider registry.terraform.io/hashicorp/google v4.6.0 + 提供者注册中心.terraform.io/hashicorp/google v4.6.0

could you please provide the similar steps for Azure platform.您能否为 Azure 平台提供类似的步骤。 I am stuck with a similar problem on my Macbook.我在我的 Macbook 上遇到了类似的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在哪里可以运行 terraform? - Where can I run terraform? 在 Apple Silicon / Big Sur 上安装 Google Cloud SDK 时出现 anthoscli 错误 - anthoscli ERROR on installing Google Cloud SDK on Apple Silicon / Big Sur 如何在 Terraform 中获取 AWS RDS 编写器实例 - How I can get the AWS RDS writer instance in Terraform 用 403 锁定我的 terraform state 文件; 如何识别执行terraform init的账户? - Locked out of my terraform state file with 403; How to identify the account performing terraform init? 如何通过 Terraform 为 cognito 用户池启用身份提供者? - How can I enable identity provider for cognito user pool via Terraform? 运行 terraform init 后无法看到 Terraform 提供程序文件 - Unable to see the Terraform provider file after running terraform init Flutter:如何获取 Apple 凭据以将 Apple 帐户链接到我的 firebase 应用程序上的帐户? - Flutter: how do I get Apple credential to link an apple account to an account on my firebase app? 如何在 Terraform 中通过标签获取所有 AWS Lambda - How can I get all AWS Lambdas by Tag in Terraform 多次运行 terraform init 是否安全 - Is it safe to run terraform init multiple times 如何将 Object 属性从我的父母传递给 Terraform 中的孩子? - How can I pass an Object Attribute from my parent to a children in Terraform?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM