Skip to content

Commit

Permalink
switch from concat to better setunion
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Dec 27, 2024
1 parent 3956227 commit 77add4c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion infra/terraform/modules/codeowners_file/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
locals {
commit_author = "CFT Bot"
commit_email = "[email protected]"
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"
Expand Down
11 changes: 3 additions & 8 deletions infra/terraform/test-org/org/github.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 77add4c

Please sign in to comment.