简体   繁体   English

GCP Cloud Build 和 Terraform 集成

[英]GCP Cloud Build and Terraform integration

I am running Terraform using Cloud Build.我正在使用 Cloud Build 运行 Terraform。

step {
  name = "hashicorp/terraform:1.0.1"
  args = ["init"]
  dir  = env/dev
}
step {
  name = "hashicorp/terraform:1.0.1"
  args = ["plan"]
  dir  = env/dev
}
step {
  name = "hashicorp/terraform:1.0.1"
  args = ["apply", "-auto-approve"]
  dir  = env/dev
}

in my terraform code there is a local-exec command which runs some Linux commands and one gcloud command.在我的 terraform 代码中有一个 local-exec 命令,它运行一些 Linux 命令和一个 gcloud 命令。

resource "null_resource" "gcloud" {
  provisioner "local-exec" {
     command = <<EOT
     .
      some Linux commads
     .
     gcloud pubsub topics list 
  EOT
  }
}

after Terraform Apply, it gives me:在 Terraform Apply 之后,它给了我:

exit status 127. Output: /bin/sh: gcloud: not found

to solve this issue I used gcloud module:为了解决这个问题,我使用了 gcloud 模块:

 module "gcloud" {
  source  = "terraform-google-modules/gcloud/google"
  version = "3.1.0"

  create_cmd_endpoint = "gcloud"
  create_cmd_body        = "version"
  destroy_cmd_body      = "gcloud"
  destroy_cmd_body       = "version"
 }

now I have two errors:现在我有两个错误:

[7:47 p.m., 2022-11-13] Milad: exit status 127. Output: /bin/sh: curl: not found
[7:47 p.m., 2022-11-13] Milad: exit status 127. Output: /bin/sh: gcloud: not found

Any help would be appreciated.任何帮助,将不胜感激。

The error that you have mentioned above seems to be due to the “gcloud” module not being incorporated properly and thus the command referencing the sub command results in this kind of error.您上面提到的错误似乎是由于“gcloud”模块未正确合并,因此引用子命令的命令导致此类错误。 The “gcloud” module execution should make sure that “gcloud” is decompressed and set up in the proper order during the setup. “gcloud”模块执行应确保“gcloud”在安装过程中以正确的顺序解压缩和设置。
I would recommend you try the latest version of terraform registry which seems to address this issue.我建议您尝试最新版本的 terraform 注册表,它似乎可以解决此问题。
Also check these similar examples:还要检查这些类似的例子:

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

相关问题 GCP 与 Terraform 集成 - GCP integration with Terraform 无法通过 Terraform 使用 GCP Cloud Build 对 GitHub 存储库进行身份验证 - Cannot authenticate GitHub repository with GCP Cloud Build via Terraform 如何在 GCP Cloud Build 的 Terraform Docker Provider 中构建和推送 docker 映像 - How to build and push a docker image in a Terraform Docker Provider by GCP Cloud Build 如何连接 Terraform 以创建从 GCP 中的私有 bitbucket 回购中提取的云构建触发器 - How to hook up Terraform to create Cloud Build Triggers that pull from a private bitbucket Repo In the GCP GCP云计费通过terraform导出到BQ - GCP cloud billing export into BQ through terraform 是否可以在Terraform中更新GCP Cloud Function的源代码? - Is it possible to update the source code of a GCP Cloud Function in Terraform? 使用 Terraform 将 GCP 云功能部署到 Artifact Registry - Deploy GCP Cloud functions to Artifact Registry using Terraform 使用 terraform 在 GCP 中创建云功能错误警报策略 - Creating a cloud-function error alerting policy in GCP with terraform 如何在 GCP 中增加云构建中的触发限制 - how to Increase trigger limit in Cloud build in GCP 通过触发器进行 GCP 云构建:Dockerfile 未找到 - GCP Cloud Build via trigger: Dockerfile not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM