generated from getindata/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
locals.tf
91 lines (87 loc) · 3.07 KB
/
locals.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
locals {
context_template = lookup(var.context_templates, var.name_scheme.context_template_name, null)
account_grants = {
for index, grant in var.account_grants : grant.all_privileges == true ? "ALL" : "CUSTOM_${index}" => grant
}
account_objects_grants = {
for index, grant in flatten([
for object_type, grants in var.account_objects_grants : [
for grant in grants :
merge(
grant,
{
object_type = object_type
}
)
]
]) : grant.all_privileges == true ? "${grant.object_type}_${grant.object_name}_ALL" : "${grant.object_type}_${grant.object_name}_CUSTOM_${index}" => grant
}
schema_grants = {
for index, schema_grant in flatten([
for grant in var.schema_grants : grant.future_schemas_in_database && grant.all_schemas_in_database ? [
merge(
grant,
{
future_schemas_in_database = true,
all_schemas_in_database = false
}
),
merge(
grant,
{
future_schemas_in_database = false,
all_schemas_in_database = true
}
)
] : [grant]
]) :
"${schema_grant.schema_name != null ? "${schema_grant.database_name}_${schema_grant.schema_name}" :
schema_grant.all_schemas_in_database != false ? "${schema_grant.database_name}_ALL_SCHEMAS" :
schema_grant.future_schemas_in_database != false ? "${schema_grant.database_name}_FUTURE_SCHEMAS" : ""
}_${schema_grant.all_privileges == true ? "ALL" : "CUSTOM_${index}"}" => schema_grant
}
schema_objects_grants = {
for index, grant in flatten([
for object_type, grants in var.schema_objects_grants : [
for grant in grants :
grant.on_all && grant.on_future ? [
merge(
grant,
{
object_type = "${object_type}S",
on_future = true,
on_all = false
}
),
merge(
grant,
{
object_type = "${object_type}S",
on_future = false,
on_all = true
}
)
] : [
merge(
grant,
{
object_type = grant.on_all || grant.on_future ? "${object_type}S" : object_type
}
)
]
]
]) : "${
grant.object_type != null && grant.object_name != null ?
"${grant.object_type}_${grant.database_name}_${grant.schema_name}_${grant.object_name}_${grant.all_privileges == true ? "ALL" : "CUSTOM_${index}"}"
: ""
}${
grant.on_all != null && grant.on_all ?
"ALL_${grant.object_type}_${grant.database_name}${grant.schema_name != null ? "_${grant.schema_name}_${grant.all_privileges == true ? "ALL" : "CUSTOM_${index}"}" : ""}"
: ""
}${
grant.on_future != null && grant.on_future ?
"FUTURE_${grant.object_type}_${grant.database_name}${grant.schema_name != null ? "_${grant.schema_name}_${grant.all_privileges == true ? "ALL" : "CUSTOM_${index}"}" : ""}"
: ""
}" => grant
}
}