-
Notifications
You must be signed in to change notification settings - Fork 0
/
locals.tf
60 lines (53 loc) · 1.92 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
locals {
org_defaults = {
role_name = "githubActions-iamRole"
allowed_branches = ["main"]
allowed_tags = []
allowed_environments = []
pull_requests = false
repositories = {
"*" = {}
}
}
github_orgs = {
for org_name, org_data in var.permissions : org_name => merge(local.org_defaults, org_data)
}
repo_defaults_by_org = {
for org_name, org_data in local.github_orgs : org_name => {
for key, val in org_data : key => val if key != "repositories"
}
}
github_orgs_with_repos = {
for org_name, org_data in local.github_orgs : org_name => merge(
{
for key, val in org_data : key => val if key != "repositories"
},
{
"repositories" = {
for repo_name, repo_data in org_data["repositories"] : repo_name => merge(local.repo_defaults_by_org[org_name], repo_data)
}
}
)
}
# [{ github_subs, role_name }]
github_subs = flatten([
for org_name, org_data in local.github_orgs_with_repos : [
for repo_name, repo_data in org_data["repositories"] : {
role_name : repo_data["role_name"]
github_subs : flatten([
[for branch in repo_data["allowed_branches"] : "repo:${org_name}/${repo_name}:ref:refs/heads/${branch}"],
[for tag in repo_data["allowed_tags"] : "repo:${org_name}/${repo_name}:ref:refs/tags/${tag}"],
[for env in repo_data["allowed_environments"] : "repo:${org_name}/${repo_name}:environment:${env}"],
[for dummy in ["DUMMY"] : "repo:${org_name}/${repo_name}:pull_request" if repo_data["pull_requests"] == true]
])
}
]
])
github_subs_by_role = {
for role in local.roles_names : role =>
flatten(matchkeys([for el in local.github_subs : el["github_subs"]], [for el in local.github_subs : el["role_name"]], [role]))
}
roles_names = distinct([
for el in local.github_subs : el["role_name"]
])
}