用于谷歌存储的静态网站的 Terraform 谷歌存储桶 - 403

ses*_*ses 3 google-cloud-platform terraform

试图为静态网站创建一个谷歌存储桶。

provider "google" {
  project = "myprojectname-123"
  credentials = "${file("storage-admin.json")}"
  region  = "us-central1"
  zone    = "us-central1-c"
}

resource "google_storage_bucket" "STANDARD" {
  name     = "mywebsite.com"
  storage_class = "STANDARD"
  location = "US"

  website {
    main_page_suffix = "index.html"
    not_found_page   = "404.html"
  }
}
Run Code Online (Sandbox Code Playgroud)

> 地形应用

googleapi:错误 403:您尝试创建的存储桶是另一个用户拥有的域名。,禁止

为 AWS找到了这个答案

问:是否可以从 Terraform for Google Cloud 创建以存储域为中心的存储/存储桶?

Joa*_*oël 5

(假设您已经验证了域 mywebsite.com,并且您是域的所有者)

我可以看到您正在使用服务的帐户凭据创建存储桶:

提供商“谷歌”{

项目=“我的项目名称-123”

凭据 = "${file("storage-admin.json")}"

区域 = "us-central1"

zone = "us-central1-c"

}

您必须将该服务帐户添加为域的所有者,因为用于创建这些资源的 terraform API 调用将使用其凭据来创建存储桶。

如果该帐户不在域的所有者列表中,您将收到 403 以及您收到的消息。有关如何将服务帐户添加为所有者的文档

同样,请确保您将服务帐户添加为域所有者,而不是站点所有者。