From 77add4c7aa27151b4c4e7b42fa848633eddbe80a Mon Sep 17 00:00:00 2001 From: Andrew Peabody Date: Fri, 27 Dec 2024 19:52:31 +0000 Subject: [PATCH] switch from concat to better setunion --- infra/terraform/modules/codeowners_file/main.tf | 2 +- infra/terraform/test-org/org/github.tf | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/infra/terraform/modules/codeowners_file/main.tf b/infra/terraform/modules/codeowners_file/main.tf index 0546fc196c3..c0d1639ce4d 100644 --- a/infra/terraform/modules/codeowners_file/main.tf +++ b/infra/terraform/modules/codeowners_file/main.tf @@ -17,7 +17,7 @@ locals { commit_author = "CFT Bot" commit_email = "cloud-foundation-bot@google.com" - owners = { for value in var.repos_map : value.name => "${join(" ", formatlist("@%s", concat(value.admins, value.maintainers)))} " if concat(value.admins, value.maintainers) > 0 } + owners = { for value in var.repos_map : value.name => "${join(" ", formatlist("@%s", setunion(lookup(value, "admins", []), lookup(value, "maintainers", []))))} " if setunion(lookup(value, "admins", []), lookup(value, "maintainers", [])) > 0 } groups = { for value in var.repos_map : value.name => "${join(" ", formatlist("@${value.org}/%s", value.groups))} " if length(value.groups) > 0 } header = "# NOTE: This file is automatically generated from values at:\n# https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/blob/master/infra/terraform/test-org/org/locals.tf\n" footer_prefix = "# NOTE: GitHub CODEOWNERS locations:\n# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-and-branch-protection\n" diff --git a/infra/terraform/test-org/org/github.tf b/infra/terraform/test-org/org/github.tf index 94efd08e0c9..cb2b3c90615 100644 --- a/infra/terraform/test-org/org/github.tf +++ b/infra/terraform/test-org/org/github.tf @@ -16,16 +16,11 @@ provider "github" {} locals { - owners = distinct( - flatten( - [for repo, val in local.repos : [for owner in concat(val.admins, val.maintainers) : lower(owner)] if try(val.admins != null || val.maintainers != null, false)] - ) + owners = flatten( + [for repo, val in local.repos : [for owner in setunion(lookup(val, "admins", []), lookup(val, "maintainers", [])) : lower(owner)]] ) - org_members = setunion( - [for login in data.github_organization.tgm.users[*].login : lower(login)], - [for login in data.github_organization.gcp.users[*].login : lower(login)] - ) + org_members = [for login in setunion(data.github_organization.tgm.users[*].login, data.github_organization.gcp.users[*].login) : lower(login)] invalid_owners = setsubtract(local.owners, local.org_members) }