93 lines
3.7 KiB
HCL
93 lines
3.7 KiB
HCL
locals {
|
|
config_files = fileset(".", "**/*.yaml")
|
|
|
|
all_configs = {
|
|
for file_path in local.config_files :
|
|
file_path => yamldecode(file(file_path))
|
|
}
|
|
|
|
gitea_configs = {
|
|
for file_path, content in local.all_configs :
|
|
file_path => content if split("/", file_path)[0] != "github.com"
|
|
}
|
|
|
|
github_configs = {
|
|
for file_path, content in local.all_configs :
|
|
file_path => merge(content, {
|
|
name = trimsuffix(basename(file_path), ".yaml")
|
|
organisation = split("/", file_path)[1]
|
|
kind = split("/", file_path)[2]
|
|
})
|
|
if split("/", file_path)[0] == "github.com"
|
|
}
|
|
|
|
config = {
|
|
organisation = {
|
|
for file_path, content in local.gitea_configs :
|
|
trimsuffix(replace(file_path, "/config.yaml", ""), ".yaml") => merge(content, {
|
|
name = split("/", file_path)[1]
|
|
gitea_url = split("/", file_path)[0]
|
|
})
|
|
if endswith(file_path, "/config.yaml") && length(split("/", file_path)) == 3
|
|
}
|
|
repository = {
|
|
for file_path, content in local.gitea_configs :
|
|
"${split("/", file_path)[0]}/${split("/", file_path)[1]}/${trimsuffix(basename(file_path), ".yaml")}" => merge(content, {
|
|
name = trimsuffix(basename(file_path), ".yaml")
|
|
organisation = split("/", file_path)[1]
|
|
gitea_url = split("/", file_path)[0]
|
|
})
|
|
if length(regexall("/repository/", file_path)) > 0
|
|
}
|
|
team = {
|
|
for file_path, content in local.gitea_configs :
|
|
"${split("/", file_path)[0]}/${split("/", file_path)[1]}/${trimsuffix(basename(file_path), ".yaml")}" => merge(content, {
|
|
name = trimsuffix(basename(file_path), ".yaml")
|
|
organisation = split("/", file_path)[1]
|
|
gitea_url = split("/", file_path)[0]
|
|
})
|
|
if length(regexall("/team/", file_path)) > 0
|
|
}
|
|
user = {
|
|
for file_path, content in local.gitea_configs :
|
|
"${split("/", file_path)[0]}/${trimsuffix(basename(file_path), ".yaml")}" => merge(content, {
|
|
username = trimsuffix(basename(file_path), ".yaml")
|
|
gitea_url = split("/", file_path)[0]
|
|
})
|
|
if length(regexall("/user/", file_path)) > 0
|
|
}
|
|
branch_protection = merge([
|
|
for file_path, content in local.gitea_configs : {
|
|
for idx, rule in try(content.branch_protection, []) :
|
|
"${split("/", file_path)[0]}/${split("/", file_path)[1]}/${trimsuffix(basename(file_path), ".yaml")}/${rule.rule_name}" => merge(rule, {
|
|
repository = trimsuffix(basename(file_path), ".yaml")
|
|
organisation = split("/", file_path)[1]
|
|
gitea_url = split("/", file_path)[0]
|
|
})
|
|
}
|
|
if length(regexall("/repository/", file_path)) > 0
|
|
]...)
|
|
deploy_key = {
|
|
for file_path, content in local.gitea_configs :
|
|
"${split("/", file_path)[0]}/${split("/", file_path)[1]}/${split("/", replace(file_path, "deploy_key/", ""))[2]}/${trimsuffix(basename(file_path), ".yaml")}" => merge(content, {
|
|
title = trimsuffix(basename(file_path), ".yaml")
|
|
repository = split("/", replace(file_path, "deploy_key/", ""))[2]
|
|
organisation = split("/", file_path)[1]
|
|
gitea_url = split("/", file_path)[0]
|
|
})
|
|
if length(regexall("/deploy_key/", file_path)) > 0
|
|
}
|
|
}
|
|
|
|
github = merge({
|
|
for kind in ["team", "ruleset", "repository"] : kind => {
|
|
for file_path, content in local.github_configs :
|
|
"${content.organisation}/${content.name}" => content
|
|
if content.kind == kind
|
|
}
|
|
}, {
|
|
# raw yaml: github_configs overwrites name with the file basename
|
|
settings = { for file_path, content in local.github_configs : content.organisation => local.all_configs[file_path] if content.kind == "config.yaml" }
|
|
})
|
|
}
|