gpt4 book ai didi

google-cloud-platform - 想要通过 terraform 将多个 Google Cloud IAM 角色分配给服务帐户

转载 作者:行者123 更新时间:2023-12-04 00:57:03 24 4
gpt4 key购买 nike

我想通过 terraform 将多个 IAM 角色分配给单个服务帐户。我准备了一个 TF 文件来执行此操作,但它有一个错误。使用单个角色可以成功分配,但使用多个 IAM 角色时会出错。

data "google_iam_policy" "auth1" {
binding {
role = "roles/cloudsql.admin"
members = [
"serviceAccount:${google_service_account.service_account_1.email}",
]
role = "roles/secretmanager.secretAccessor"
members = [
"serviceAccount:${google_service_account.service_account_1.email}",
]
role = "roles/datastore.owner"
members = [
"serviceAccount:${google_service_account.service_account_1.email}",
]
role = "roles/storage.admin"
members = [
"serviceAccount:${google_service_account.service_account_1.email}",
]
}
}
如何为单个服务帐户分配多个角色?

最佳答案

根据documentation

Each document configuration must have one or more binding blocks, which each accept the following arguments: ....



你必须重复绑定(bind),像这样
data "google_iam_policy" "auth1" {
binding {
role = "roles/cloudsql.admin"
members = [
"serviceAccount:${google_service_account.service_account_1.email}",
]
}
binding {
role = "roles/secretmanager.secretAccessor"
members = [
"serviceAccount:${google_service_account.service_account_1.email}",
]
}
binding {
role = "roles/datastore.owner"
members = [
"serviceAccount:${google_service_account.service_account_1.email}",
]
}
binding {
role = "roles/storage.admin"
members = [
"serviceAccount:${google_service_account.service_account_1.email}",
]
}
}

使用 gcloud 命令也是如此,您一次只能在电子邮件列表中添加 1 个角色。

关于google-cloud-platform - 想要通过 terraform 将多个 Google Cloud IAM 角色分配给服务帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61661116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com