-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiam.tf
46 lines (35 loc) · 1.57 KB
/
iam.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
locals {
# filter all objects that define a single role
iam_role = [for iam in var.iam : iam if can(iam.role)]
# filter all objects that define multiple roles and expand them to single roles
iam_roles = flatten([for iam in var.iam :
[for role in iam.roles : merge(iam, { role = role })] if can(iam.roles)
])
iam = concat(local.iam_role, local.iam_roles)
iam_map = { for idx, iam in local.iam :
try(iam._key, iam.role) => iam
}
}
module "iam" {
source = "github.com/mineiros-io/terraform-google-service-account-iam.git?ref=v0.2.0"
# Hack ternary in Terraform to prevent
# "Error: Inconsistent conditional result types"
# "The true and false result expressions must have consistent types."
for_each = [local.iam_map, {}][var.policy_bindings == null ? 0 : 1]
module_enabled = var.module_enabled
module_depends_on = var.module_depends_on
service_account_id = try(google_service_account.service_account[0].name, null)
role = each.value.role
members = try(each.value.members, [])
computed_members_map = var.computed_members_map
authoritative = try(each.value.authoritative, true)
}
module "policy_bindings" {
source = "github.com/mineiros-io/terraform-google-service-account-iam.git?ref=v0.2.0"
count = var.policy_bindings != null ? 1 : 0
module_enabled = var.module_enabled
module_depends_on = var.module_depends_on
service_account_id = try(google_service_account.service_account[0].name, null)
policy_bindings = var.policy_bindings
computed_members_map = var.computed_members_map
}