I'm using the following
resource "google_service_account" "store_user" {
account_id = "store-user"
display_name = "Storage User"
}
resource "google_project_iam_binding" "store_user" {
project = var.project_id
role = "roles/storage.admin"
members = [
"serviceAccount:${google_service_account.store_user.email}"
]
}
Which works well, in that it creates the SA and assigns it the storage admin role. Great. But I need to give this SA about 4 roles. I have tried all manner of things, including using a data block with repeating bindings/roles blocks like this:
data "google_iam_policy" "store_user_roles" {
binding {
role = "roles/storage.admin"
members = [
"serviceAccount:${google_service_account.store_user.email}",
]
}
binding {
role = "roles/pubsub.admin"
members = [
"serviceAccount:${google_service_account.store_user.email}",
]
}
}
Oddly, that runs, but the SA does not get the roles/permissions. I've tried various other examples I've found here and there but with no success. Can someone please give me a shove in the right direction for how to accomplish this?
// Update. The following did work for me:
resource "google_project_iam_binding" "storage-iam" {
project = var.project_id
role = "roles/storage.admin"
members = [
"serviceAccount:${google_service_account.store_user.email}",
]
}
resource "google_project_iam_binding" "pubsub-iam" {
project = var.project_id
role = "roles/pubsub.admin"
members = [
"serviceAccount:${google_service_account.store_user.email}",
]
}