generated from getindata/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locals.tf
78 lines (75 loc) · 2.61 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
locals {
context_template = lookup(var.context_templates, var.name_scheme.context_template_name, null)
database_role_name = "${snowflake_database_role.this.database}.${snowflake_database_role.this.name}"
database_grants = var.database_grants.all_privileges == null && var.database_grants.privileges == null ? {} : {
var.database_grants.all_privileges == true ? "ALL" : "CUSTOM" = var.database_grants
}
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.schema_name :
schema_grant.all_schemas_in_database != false ? "ALL_SCHEMAS" :
schema_grant.future_schemas_in_database != false ? "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.object_name}_${grant.all_privileges == true ? "ALL" : "CUSTOM"}"
: ""
}${
grant.on_all != null && grant.on_all ?
"_ALL_${grant.object_type}${grant.schema_name != null ? "_${grant.schema_name}_${grant.all_privileges == true ? "ALL" : "CUSTOM"}" : ""}"
: ""
}${
grant.on_future != null && grant.on_future ?
"_FUTURE_${grant.object_type}${grant.schema_name != null ? "_${grant.schema_name}_${grant.all_privileges == true ? "ALL" : "CUSTOM"}" : ""}"
: ""
}" => grant
}
}