我使用 Google Cloud Storage Buckets 创建的 Terraform 后端状态很奇怪?想法?

Adr*_*ron 1 google-cloud-platform terraform

我正在使用 Terraform 设置远程后端来管理状态。I\xe2\x80\x99ve 设置了一个 connection.tf 文件,用于连接和声明 Terraform 状态文件的 GCS。文件内容如下所示。

\n\n
provider "google" {\n  credentials = "${file("../../secrets/account-thrashingcode.json")}"\n  project     = "thrashingcorecode"\n  region      = "us-west1"\n}\n\nterraform {\n  backend "gcs" {\n    bucket  = "terraform-remote-states"\n    path    = "dev/terraform.tfstate"\n    project = "thrashingcorecode"\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

资源 I\xe2\x80\x99ve 设置(至少对于本示例而言)是在 GCP 中创建默认网络的超级简单配置。该配置看起来像这样。

\n\n
data "google_compute_network" "my-network" {\n  name = "default-us-west1"\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

现在,当我运行 terraform init 时,出现此错误。

\n\n
$ terraform init\n\nInitializing the backend...\n\nSuccessfully configured the backend "gcs"! Terraform will automatically\nuse this backend unless the backend configuration changes.\nError refreshing state: [WARN] Error retrieving object blue-world-terraform-state/dev/terraform.tfstate: googleapi: got HTTP response code 403 with body: adronsotheremail@gmail.com does not have storage.objects.get access to blue-world-terraform-state/dev/terraform.tfstate.\nThis leaves me with a few questions.\n
Run Code Online (Sandbox Code Playgroud)\n\n

Terraform 从哪里派生 \xe2\x80\x9cadronsotheremail@gmail.com\xe2\x80\x9d 电子邮件身份作为尝试访问存储位置的帐户?\xe2\x80\x99t 实际上似乎与我创建资源的帐户关联的电子邮件地址相同。\n如果我最初可以使用在第 1 阶段拥有所有权的服务帐户创建资源,那么它的用途是什么在这种特殊情况下的权限?它确实存在,如图所示:

\n\n

资源存在

\n\n

我第一次尝试解决此问题是转到存储资源并添加此帐户以确保它具有对此资源的权限。

\n\n

在此输入图像描述

\n\n

这解决了问题,但我\xe2\x80\x99m 仍然不完全确定为什么我必须添加成员。当理论上我认为我正在使用连接中的connection.tf 文件中详细的连接信息时,难道不应该创建 Terraform 吗?

\n\n

参考:我已经进一步详细阐述了整个过程以及我在这里所做的工作的多个阶段。

\n

kom*_*oma 5

关键问题是:

\n\n
\n

“Terraform 从哪里派生 \xe2\x80\x9cadronsotheremail@gmail.com\xe2\x80\x9d email\n 身份作为尝试访问存储位置的帐户?”

\n
\n\n

答案是它从应用程序默认凭据中获取帐户。要切换到不同的默认凭据,请运行:

\n\n
\n

gcloud auth 应用程序-默认登录

\n
\n\n

也可以看看: https: //cloud.google.com/docs/authentication/product

\n