about summary refs log tree commit diff
path: root/ops/github/repositories.tf
blob: 38e5de27b605aa68d499f93d44aa6fbc18d81054 (plain) (blame)
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
locals {
  repositories = yamldecode(file("repositories.yaml"))
}

resource "github_repository" "repos" {
  for_each = local.repositories

  name                   = try(each.value.name, each.key)
  visibility             = each.value.visibility
  archived               = try(each.value.archived, false)
  description            = try(each.value.description, null)
  has_downloads          = false
  has_issues             = try(each.value.has_issues, true)
  has_projects           = false
  has_wiki               = false
  allow_merge_commit     = true
  allow_squash_merge     = false
  allow_rebase_merge     = false
  vulnerability_alerts   = try(each.value.vulnerability_alerts, false)
  delete_branch_on_merge = try(!each.value.archived, true)
  auto_init              = true
}

resource "github_branch_default" "main" {
  depends_on = [github_repository.repos]
  # no need to set the default branch if the repository is already
  # archived.
  # use the name for the repository if set
  for_each = {
    for k, v in local.repositories : try(v.name, k) => v
    if try(v.archived, false) == false
  }

  repository = each.key
  branch     = try(each.value.default_branch, "main")
}