This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
48 lines (42 loc) · 1.83 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
resource "google_service_account" "this" {
project = var.project_id
account_id = var.name
description = "Managed By Terraform"
display_name = var.display_name
}
resource "google_project_iam_member" "this" {
for_each = toset(var.project_roles)
project = var.project_id
role = each.value
member = "serviceAccount:${google_service_account.this.email}"
}
resource "google_project_iam_member" "external" {
for_each = toset(var.external_project_roles)
project = element(split("=>", each.value), 0, )
role = element(split("=>", each.value), 1, )
member = "serviceAccount:${google_service_account.this.email}"
}
resource "google_storage_bucket_iam_member" "this" {
for_each = toset(var.bucket_roles)
bucket = element(split("=>", each.value), 0, )
role = element(split("=>", each.value), 1, )
member = "serviceAccount:${google_service_account.this.email}"
}
resource "google_secret_manager_secret_iam_member" "this" {
for_each = toset(var.secret_roles)
secret_id = element(split("=>", each.value), 0, )
role = element(split("=>", each.value), 1, )
member = "serviceAccount:${google_service_account.this.email}"
}
resource "google_service_account_iam_member" "this" {
for_each = toset(var.service_account_roles)
service_account_id = element(split("=>", each.value), 0, ) == "this" ? google_service_account.this.name : element(split("=>", each.value.role), 0, )
role = element(split("=>", each.value), 1, )
member = "serviceAccount:${google_service_account.this.email}"
}
resource "google_service_account_iam_member" "members" {
for_each = toset(var.members)
service_account_id = google_service_account.this.name
role = element(split("=>", each.value), 1, )
member = element(split("=>", each.value), 0, )
}