-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.tf
58 lines (49 loc) · 1.73 KB
/
helpers.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
locals {
helper_is_account = {
for id, conf in local.config_data :
(conf.account.name) => (data.aws_caller_identity.this.account_id == id)
if lookup(conf, "grouping", {}) == lookup(local.current_config, "grouping", {})
}
helper_is_env = {
for env in toset(compact(concat([""], [
for account in local.config_data :
keys(lookup(account, "environments", {}))
if lookup(account, "grouping", {}) == lookup(local.current_config, "grouping", {})
]...))) : env => (env == local.current_env_name)
}
helper_grouping_keys = try(toset(concat([
for acc in local.config_data :
keys(lookup(acc, "grouping", {}))
]...)), [])
helper_is_group = {
for key in local.helper_grouping_keys :
key => {
for value in toset([
for acc in local.config_data :
lookup(lookup(acc, "grouping", {}), key, [])
]) : value => lookup(lookup(local.current_config, "grouping", {}), key, []) == value
}
}
helper_is = merge(local.helper_is_group, {
// Is account helper
account = merge({
unknown = !anytrue(values(local.helper_is_account))
}, local.helper_is_account)
// Is environment helper
env = merge({
// Special helper to always reflect current env as true
(local.current_env_name) = true
// Whether environment is unknown
unknown = !anytrue(values(local.helper_is_env))
}, local.helper_is_env)
// Is a build environment
build = (local.current_build_name != null)
// Is a deployment environment
deployment = (local.current_deployment_name != null)
// Is account and environment unknown to config
unknown = !anytrue(concat(
values(local.helper_is_account),
values(local.helper_is_account),
))
})
}