Google cloud storage 如何在多个服务帐户上分配多个google_storage_bucket_iam_成员

Google cloud storage 如何在多个服务帐户上分配多个google_storage_bucket_iam_成员,google-cloud-storage,terraform-provider-gcp,terraform0.12+,Google Cloud Storage,Terraform Provider Gcp,Terraform0.12+,使用地形0.12.24 我创建了多个服务帐户,并希望将拥有所有者权限的每个帐户分配到一个存储桶列表中,并遇到许多问题 # Service-accounts created with random-integer suffix resource "google_service_account" "sample_accounts" { for_each = {for proj in var.target_projects: proj => proj} account_id

使用地形0.12.24

我创建了多个服务帐户,并希望将拥有所有者权限的每个帐户分配到一个存储桶列表中,并遇到许多问题

# Service-accounts created with random-integer suffix
resource "google_service_account" "sample_accounts" {
  for_each     = {for proj in var.target_projects: proj => proj}
  account_id   = "cost-saver-${random_integer.sa_id[each.key].result}" 
  project      = var.project
  display_name = "service account for ${each.key}"
}
由于服务帐户是动态创建的,并且我希望在相同的terraform应用运行中使用它们,因此我遇到了这个问题

Error: Invalid for_each argument

  on main.tf line 138, in resource "google_storage_bucket_iam_member" "shared_buckets_iam":
 138:   for_each    = {for svc in google_service_account.sample_accounts: svc.email => svc.email}

The "for_each" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the for_each depends on.

我能得到一些帮助吗?

您需要什么帮助?terraforms的错误信息非常清楚,不是吗?terraforms建议我使用-target创建一个资源,然后创建另一个,这可能是更糟糕的方法,并破坏了自动化的整个目的。如果我可以创建其他项目,如google_dns_记录并动态检索它们的属性,那么必须有一种方法来检索google_服务_帐户。为什么需要创建一组服务帐户?这是应用程序的要求。每一个都用于在不同的项目中部署云功能,以后onOk,您不想重复代码,只需循环,甚至用于部署功能,对吗?您需要什么帮助?terraforms的错误信息非常清楚,不是吗?terraforms建议我使用-target创建一个资源,然后创建另一个,这可能是更糟糕的方法,并破坏了自动化的整个目的。如果我可以创建其他项目,如google_dns_记录并动态检索它们的属性,那么必须有一种方法来检索google_服务_帐户。为什么需要创建一组服务帐户?这是应用程序的要求。每一个都用于在不同的项目中部署云函数,以后onOk,您不想重复代码,只循环,甚至用于部署函数,对吗?
Error: Invalid for_each argument

  on main.tf line 138, in resource "google_storage_bucket_iam_member" "shared_buckets_iam":
 138:   for_each    = {for svc in google_service_account.sample_accounts: svc.email => svc.email}

The "for_each" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the for_each depends on.