locals { config_files = fileset(".", "**/*.yaml") all_configs = { for file_path in local.config_files : file_path => yamldecode(file(file_path)) } config = { organisation = { for file_path, content in local.all_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.all_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.all_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 } branch_protection = merge([ for file_path, content in local.all_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.all_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 } } }