forked from mineiros-io/terraform-google-project-iam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
116 lines (86 loc) · 3.04 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
locals {
create_binding = var.policy_bindings == null && var.role != null && var.authoritative
create_member = var.policy_bindings == null && var.role != null && var.authoritative == false
create_policy = var.policy_bindings != null
}
resource "google_project_iam_binding" "binding" {
count = var.module_enabled && local.create_binding ? 1 : 0
depends_on = [var.module_depends_on]
project = var.project
role = var.role
members = [for m in var.members : try(var.computed_members_map[regex("^computed:(.*)", m)[0]], m)]
dynamic "condition" {
for_each = var.condition != null ? [var.condition] : []
content {
expression = condition.value.expression
title = condition.value.title
description = try(condition.value.description, null)
}
}
}
resource "google_project_iam_member" "member" {
for_each = var.module_enabled && local.create_member ? var.members : []
project = var.project
role = var.role
member = try(var.computed_members_map[regex("^computed:(.*)", each.value)[0]], each.value)
dynamic "condition" {
for_each = var.condition != null ? [var.condition] : []
content {
expression = condition.value.expression
title = condition.value.title
description = try(condition.value.description, null)
}
}
}
resource "google_project_iam_policy" "policy" {
count = var.module_enabled && local.create_policy ? 1 : 0
project = var.project
policy_data = try(data.google_iam_policy.policy[0].policy_data, null)
depends_on = [var.module_depends_on]
}
data "google_iam_policy" "policy" {
count = var.module_enabled && var.policy_bindings != null ? 1 : 0
dynamic "binding" {
for_each = var.policy_bindings
content {
role = binding.value.role
members = [for m in binding.value.members : try(var.computed_members_map[regex("^computed:(.*)", m)[0]], m)]
dynamic "condition" {
for_each = try([binding.value.condition], [])
content {
expression = condition.value.expression
title = condition.value.title
description = try(condition.value.description, null)
}
}
}
}
dynamic "audit_config" {
for_each = var.audit_configs
content {
service = audit_config.value.service
dynamic "audit_log_configs" {
for_each = audit_config.value.audit_log_configs
content {
log_type = audit_log_configs.value.log_type
exempted_members = try(audit_log_configs.value.expected_members, null)
}
}
}
}
}
locals {
audit_configs_map = { for c in var.audit_configs : c.service => c }
}
resource "google_project_iam_audit_config" "project" {
for_each = var.module_enabled && !local.create_policy ? local.audit_configs_map : {}
project = var.project
service = each.value.service
dynamic "audit_log_config" {
for_each = each.value.audit_log_configs
content {
log_type = audit_log_config.value.log_type
exempted_members = try(audit_log_config.value.exempted_members, null)
}
}
}