-
Notifications
You must be signed in to change notification settings - Fork 8
/
locals.tf
55 lines (47 loc) · 1.2 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
locals {
pack_file = yamldecode(file("${path.module}/files/pack-rules.yaml"))
rule_packs_to_apply = [
for pack in var.rule_packs :
local.pack_file["packs"][pack]
]
rule_packs_to_exclude = [
for pack in var.rule_packs_to_exclude :
local.pack_file["packs"][pack]
]
rules_collected = sort(
distinct(
flatten(
concat(
var.rules_to_include,
local.rule_packs_to_apply
)
)
)
)
rules_exclude_collected = sort(
distinct(
flatten(
concat(
var.rules_to_exclude,
local.rule_packs_to_exclude
)
)
)
)
final_rules = [
for rule in local.rules_collected :
rule if !contains(local.rules_exclude_collected, rule)
]
combined_rules = {
for rule in distinct(concat(keys(local.managed_rules), keys(var.rule_overrides))) :
rule => lookup(local.managed_rules, rule, lookup(var.rule_overrides, rule, {}))
}
final_managed_rules = {
for rule, attr in local.combined_rules :
rule => merge(attr, lookup(var.rule_overrides, rule, {}))
}
rules_to_apply = {
for rule, attr in local.final_managed_rules :
rule => attr if contains(local.final_rules, rule)
}
}