Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ locals {
".commitlintrc.yml" = {
content = file("templates/all/.commitlintrc.yml")
},
".cspell.config.yaml" = {
content = file("templates/all/.cspell.config.yaml")
},
".make/base.mk" = {
content = file("templates/all/.make/base.mk")
},
Expand All @@ -56,6 +53,15 @@ locals {
content = file("templates/all/CONTRIBUTING.md")
},
}

# Files seeded with initial content on repository creation.
# The repository owns these files afterwards, Terraform will not update them.
seeded_files = {
".cspell.config.yaml" = {
content = file("templates/all/.cspell.config.yaml")
},
}

template_files = {
".github/CODEOWNERS" = "templates/all/.github/CODEOWNERS.tftpl"
"Makefile" = "templates/all/Makefile"
Expand Down Expand Up @@ -171,6 +177,8 @@ module "repository" {
try(each.value.repository_files, {})
)

seeded_repository_files = local.seeded_files

collaborators = try(each.value.collaborators, {})

default_branch_protection_settings = try(each.value.default_branch_protection_settings, {})
Expand Down
37 changes: 35 additions & 2 deletions src/modules/github-repository/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ resource "github_branch_protection" "protection" {
depends_on = [
github_branch.branch,
github_repository_environment.env,
github_repository_file.files
github_repository_file.files,
github_repository_file.seeded_files
]
}

Expand All @@ -177,7 +178,8 @@ resource "github_branch_protection" "all" {
depends_on = [
github_branch.branch,
github_repository_environment.env,
github_repository_file.files
github_repository_file.files,
github_repository_file.seeded_files
]
}

Expand Down Expand Up @@ -216,6 +218,37 @@ resource "github_repository_file" "files" {
depends_on = [github_repository_file.init]
}

########################################################
#
# Provision seeded repository files
# These files are created with initial content, but
# owned by the repository afterwards. Terraform will
# not update them after creation.
#
########################################################
resource "github_repository_file" "seeded_files" {
for_each = var.seeded_repository_files

repository = github_repository.repository.name
branch = github_branch_default.default.branch

file = each.key
content = each.value.content
overwrite_on_create = each.value.overwrite_on_create

commit_message = "fixup! ci: terraform provisioned file changes\n\n[skip ci]"
depends_on = [github_repository_file.init]

lifecycle {
ignore_changes = [content]
}
}

moved {
from = github_repository_file.files[".cspell.config.yaml"]
to = github_repository_file.seeded_files[".cspell.config.yaml"]
}

########################################################
#
# Create webhooks
Expand Down
9 changes: 9 additions & 0 deletions src/modules/github-repository/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,12 @@ variable "repository_files" {
}))
default = {}
}

variable "seeded_repository_files" {
description = "List of files that should be provisioned with initial content when the repository is created, but never updated afterwards. The repository owns these files after creation."
type = map(object({
content = string
overwrite_on_create = optional(bool, true)
}))
default = {}
}
1 change: 1 addition & 0 deletions src/repositories_embedded.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module "repository_stm32" {
}
}
)
seeded_repository_files = local.seeded_files

# Settings with defaults
owner_team = each.value.owner_team
Expand Down
1 change: 1 addition & 0 deletions src/repositories_pod.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module "repository_pod" {
}
}
)
seeded_repository_files = local.seeded_files

# Settings with defaults
owner_team = each.value.owner_team
Expand Down
4 changes: 4 additions & 0 deletions src/repositories_templates.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ module "repository_emb_template" {
) } }
)

seeded_repository_files = local.seeded_files

default_branch_protection_settings = each.value.default_branch_protection_settings
}

Expand Down Expand Up @@ -108,5 +110,7 @@ module "repository_pod_template" {
) } }
)

seeded_repository_files = local.seeded_files

default_branch_protection_settings = each.value.default_branch_protection_settings
}
6 changes: 6 additions & 0 deletions src/repositories_terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ module "repository_tf" {
}
)

seeded_repository_files = local.seeded_files

collaborators = {
maintainers = ["services"]
}
Expand Down Expand Up @@ -163,6 +165,8 @@ module "repository_tf_gcp" {
}
)

seeded_repository_files = local.seeded_files

collaborators = {
maintainers = ["services"]
}
Expand Down Expand Up @@ -199,6 +203,8 @@ module "repository_tf_mod" {
}
)

seeded_repository_files = local.seeded_files

collaborators = {
maintainers = ["services"]
}
Expand Down
Loading