要使用Terraform在GCP中部署具有公共可读存储对象许可权的存储桶

问题描述 投票:0回答:1

我创建了一个terraform文件,以创建具有公共可读存储对象权限的Google存储桶。我能够部署存储桶,但无法为模板分配正确的ACL,但我发现ACL部件有一些错误。

provider "google-beta" {
  project = "${var.project}"
}

 resource "google_storage_default_object_access_control" "public_rule" {
  bucket = "google_storage_bucket.test-${var.project}"
  role   = "READER"
  entity = "allUsers"
 }

resource "google_storage_bucket" "bucket" {
  name = "test-${var.project}"
  storage_class = "standard"
  location = "US"
}

错误:附加了enter image description here

如果在创建存储桶时有人可以帮助我分配权限,那将非常有用。

google-cloud-platform google-cloud-storage terraform terraform-provider-gcp terraform-template-file
1个回答
0
投票

根据Terraform Official Documentation,使用功能“ bucket.name”,它从变量“名称”中读取存储桶名称。另外,您还必须在resource_storage_bucket中提供您的项目ID,如下所示。我尝试了一下,对我来说它正常工作:

provider "google-beta" {
}
 resource "google_storage_default_object_access_control" "public_rule" {
  bucket = google_storage_bucket.bucket.name
  role   = "READER"
  entity = "allUsers"
 }
resource "google_storage_bucket" "bucket" {
  name = "[THE_BUCKET_NAME]"
  project = "[PROJECT_ID]"
  storage_class = "standard"
  location = "US"

其中PROJECT_ID是您的项目ID,THE_BUCKET_NAME是您要添加的存储桶名称。

© www.soinside.com 2019 - 2024. All rights reserved.