Add declarative fork support to repository config #96
@@ -4,167 +4,167 @@ import {
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/puppet-prod"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/puppet-prod"].gitea_repository.this[0]
|
||||
id = "2"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/puppet-r10k"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/puppet-r10k"].gitea_repository.this[0]
|
||||
id = "3"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-gonic"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-gonic"].gitea_repository.this[0]
|
||||
id = "23"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/docker-almalinux-base"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/docker-almalinux-base"].gitea_repository.this[0]
|
||||
id = "24"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-internal-ca-certificates"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-internal-ca-certificates"].gitea_repository.this[0]
|
||||
id = "27"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-template"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-template"].gitea_repository.this[0]
|
||||
id = "29"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-jellyfin-web"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-jellyfin-web"].gitea_repository.this[0]
|
||||
id = "31"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-proxlb"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuild-proxlb"].gitea_repository.this[0]
|
||||
id = "33"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/docker-almalinux-buildrunner"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/docker-almalinux-buildrunner"].gitea_repository.this[0]
|
||||
id = "36"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/docker-template"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/docker-template"].gitea_repository.this[0]
|
||||
id = "38"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/terraform-vault"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/terraform-vault"].gitea_repository.this[0]
|
||||
id = "39"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/docker-almalinux-jupyterinstance"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/docker-almalinux-jupyterinstance"].gitea_repository.this[0]
|
||||
id = "40"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuilder"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/rpmbuilder"].gitea_repository.this[0]
|
||||
id = "41"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/docker-almalinux-runnerdnd"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/docker-almalinux-runnerdnd"].gitea_repository.this[0]
|
||||
id = "43"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/initbuilder"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/initbuilder"].gitea_repository.this[0]
|
||||
id = "47"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/puppetapi"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/puppetapi"].gitea_repository.this[0]
|
||||
id = "50"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/terraform-nomad"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/terraform-nomad"].gitea_repository.this[0]
|
||||
id = "53"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/packer-images"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/packer-images"].gitea_repository.this[0]
|
||||
id = "59"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/app-sudaporn-research-normalised"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/app-sudaporn-research-normalised"].gitea_repository.this[0]
|
||||
id = "60"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/app-sudaporn-research-individual"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/app-sudaporn-research-individual"].gitea_repository.this[0]
|
||||
id = "63"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/terraform-incus"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/terraform-incus"].gitea_repository.this[0]
|
||||
id = "66"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/artifactapi"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/artifactapi"].gitea_repository.this[0]
|
||||
id = "67"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/argocd-apps"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/argocd-apps"].gitea_repository.this[0]
|
||||
id = "100"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/certmanager"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/certmanager"].gitea_repository.this[0]
|
||||
id = "101"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/node-lookup"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/node-lookup"].gitea_repository.this[0]
|
||||
id = "102"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/container-devcompute"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/container-devcompute"].gitea_repository.this[0]
|
||||
id = "135"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/streamstack"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/streamstack"].gitea_repository.this[0]
|
||||
id = "136"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/terraform-provider-artifactapi"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/terraform-provider-artifactapi"].gitea_repository.this[0]
|
||||
id = "137"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/forgebot"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/forgebot"].gitea_repository.this[0]
|
||||
id = "139"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/forgebot-skills"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/forgebot-skills"].gitea_repository.this[0]
|
||||
id = "140"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/container-agent-base"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/container-agent-base"].gitea_repository.this[0]
|
||||
id = "141"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/container-agent-dev"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/container-agent-dev"].gitea_repository.this[0]
|
||||
id = "142"
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/container-agent-infra"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/container-agent-infra"].gitea_repository.this[0]
|
||||
id = "143"
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ import {
|
||||
}
|
||||
|
||||
import {
|
||||
to = module.repository["git.unkin.net/unkin/terraform-git"].gitea_repository.this
|
||||
to = module.repository["git.unkin.net/unkin/terraform-git"].gitea_repository.this[0]
|
||||
id = "144"
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ module "repository" {
|
||||
|
||||
name = each.value.name
|
||||
organisation = each.value.organisation
|
||||
fork_from = each.value.fork_from
|
||||
description = each.value.description
|
||||
private = each.value.private
|
||||
default_branch = each.value.default_branch
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
locals {
|
||||
fork_source = var.fork_from == null ? null : split("/", var.fork_from)
|
||||
}
|
||||
|
||||
resource "gitea_repository" "this" {
|
||||
count = var.fork_from == null ? 1 : 0
|
||||
|
||||
username = var.organisation
|
||||
name = var.name
|
||||
description = var.description
|
||||
@@ -33,3 +39,17 @@ resource "gitea_repository" "this" {
|
||||
ignore_changes = [migration_mirror_interval]
|
||||
}
|
||||
}
|
||||
|
||||
moved {
|
||||
from = gitea_repository.this
|
||||
to = gitea_repository.this[0]
|
||||
}
|
||||
|
||||
# gitea_fork has no archive_on_destroy, so removing a fork from the config deletes the repository instead of archiving it.
|
||||
resource "gitea_fork" "this" {
|
||||
count = var.fork_from == null ? 0 : 1
|
||||
|
||||
owner = local.fork_source[0]
|
||||
repo = local.fork_source[1]
|
||||
organization = var.organisation
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
output "id" {
|
||||
value = gitea_repository.this.id
|
||||
value = one(concat(gitea_repository.this[*].id, gitea_fork.this[*].id))
|
||||
}
|
||||
|
||||
@@ -6,6 +6,22 @@ variable "organisation" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "fork_from" {
|
||||
description = "Source repository to fork, as \"<owner>/<repo>\". When set, a fork is created instead of a new repository."
|
||||
type = string
|
||||
default = null
|
||||
|
||||
validation {
|
||||
condition = var.fork_from == null || can(regex("^[^/]+/[^/]+$", var.fork_from))
|
||||
error_message = "fork_from must be \"<owner>/<repo>\"."
|
||||
}
|
||||
|
||||
validation {
|
||||
condition = var.fork_from == null || try(split("/", var.fork_from)[1], null) == var.name
|
||||
error_message = "fork_from source repository must be named \"${var.name}\": a fork inherits the source name, so it cannot differ from the config file name."
|
||||
}
|
||||
}
|
||||
|
||||
variable "description" {
|
||||
type = string
|
||||
default = null
|
||||
|
||||
@@ -17,6 +17,7 @@ variable "repository" {
|
||||
type = map(object({
|
||||
name = string
|
||||
organisation = string
|
||||
fork_from = optional(string)
|
||||
description = optional(string)
|
||||
private = optional(bool)
|
||||
default_branch = optional(string)
|
||||
@@ -44,6 +45,19 @@ variable "repository" {
|
||||
migration_releases = optional(bool)
|
||||
}))
|
||||
default = {}
|
||||
|
||||
validation {
|
||||
condition = alltrue([
|
||||
for key, repo in var.repository :
|
||||
length([for attribute, value in repo : attribute if value != null && !contains(["name", "organisation", "fork_from"], attribute)]) == 0
|
||||
if repo.fork_from != null
|
||||
])
|
||||
error_message = "gitea_fork only takes the source repository and the owning organisation, so fork_from cannot be combined with other repository settings: ${join("; ", [
|
||||
for key, repo in var.repository :
|
||||
"${key} also sets ${join(", ", [for attribute, value in repo : attribute if value != null && !contains(["name", "organisation", "fork_from"], attribute)])}"
|
||||
if repo.fork_from != null && length([for attribute, value in repo : attribute if value != null && !contains(["name", "organisation", "fork_from"], attribute)]) > 0
|
||||
])}."
|
||||
}
|
||||
}
|
||||
|
||||
variable "branch_protection" {
|
||||
|
||||
Reference in New Issue
Block a user