From 520184ddd5a3378c6f63198302826be6a54da5b1 Mon Sep 17 00:00:00 2001 From: Alexey Zhokhov Date: Sun, 11 Oct 2026 20:57:33 +0700 Subject: [PATCH 1/4] docs: unify README with the shared github-terraform skeleton Same section order and wording as the other github-terraform repos: Layout, Authentication, Adding a repository, Verification. Documents the ambient GITHUB_TOKEN requirement and the mandatory-list step in checks.tf when adding a repository. Signed-off-by: Alexey Zhokhov --- README.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f9c6c5b..ced9173 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,21 @@ settings plus `protect-main` and `protect-tags` rulesets. - `imports.tf` — bootstrap import triples (one per repo: settings + 2 rulesets). - `providers.tf`, `versions.tf`, `outputs.tf` — provider, pins, outputs. +## Authentication + +Run tofu with `GITHUB_TOKEN` exported in the shell; the GitHub provider +reads it from the environment. The token needs Administration: write on +every managed repository. + ## Adding a repository 1. Add one entry to `repository_policies` in `variables.tf`, copying a check - list from `locals.tf` (`standard` = `["Required", "DCO"]`, - `policy` = `["Policy"]`); bespoke checks inline with a comment citing the - producing workflow. Repos with no CI use `required_checks = []` plus a - non-empty `no_ci_reason` and extend the allowlist check in `checks.tf`. + list from `locals.tf` (`standard` = `["Required", "DCO"]`, `policy` = + `["Policy"]`); bespoke checks inline with a comment citing the producing + workflow. Repos with no CI use `required_checks = []` plus a non-empty + `no_ci_reason`, extend the allowlist check in `checks.tf`, and add the + name to the mandatory list in `mandatory_target_repositories_present` in + `checks.tf` (updating its count and message). 2. Add one import triple (settings + `protect_main` + `protect_tags`) to `imports.tf` using the live numeric ruleset IDs. @@ -31,3 +39,6 @@ tofu fmt -check -recursive tofu init -backend=false -input=false -lockfile=readonly tofu validate -no-color ``` + +OpenTofu is pinned via `mise.toml` (opentofu 1.13.1); existing repos are +imported via `imports.tf` on first apply. From 75fa58d96c643cdf4614897b6581169555193729 Mon Sep 17 00:00:00 2001 From: Alexey Zhokhov Date: Sun, 11 Oct 2026 20:57:33 +0700 Subject: [PATCH 2/4] docs: add pull request template Signed-off-by: Alexey Zhokhov --- .github/PULL_REQUEST_TEMPLATE.md | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..3c93d00 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,81 @@ + + +## Related pull requests + + + +- + +## Summary + + + +## What ships + + + +- +- + +## Behavior changes + + + +- + +## What this addresses + + + +- + +## Not included + + + +- + +## Verify locally + +### Checkout + +```sh +gh pr checkout +``` + +### Static checks + + + +```sh +tofu fmt -check -recursive +tofu init -backend=false -input=false -lockfile=readonly +tofu validate -no-color +``` + +### Smoke + + + +```sh +tofu plan -no-color +``` + +Expected: . + +## Migration notes + + From e0693bf65eebeed9f4dcf9ab29fafafa598c9aa4 Mon Sep 17 00:00:00 2001 From: Alexey Zhokhov Date: Sun, 11 Oct 2026 22:13:07 +0700 Subject: [PATCH 3/4] feat: manage organization settings and add mise tofu tasks Signed-off-by: Alexey Zhokhov --- README.md | 16 +++++++++++++--- imports.tf | 15 +++++++++++++++ mise.toml | 22 ++++++++++++++++++++++ organization.tf | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ outputs.tf | 4 ++++ 5 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 organization.tf diff --git a/README.md b/README.md index ced9173..2e062f1 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ settings plus `protect-main` and `protect-tags` rulesets. - `variables.tf` — `repository_policies` inventory (single source of truth). - `locals.tf` — `check_templates` copy-paste source for check lists. - `repositories.tf` — `module.repository_policy` wiring. +- `organization.tf` — organization settings and Actions/workflow permissions. - `modules/repository-policy/` — shared policy module (identical across orgs). - `checks.tf` — invariant guards (no scripts). - `imports.tf` — bootstrap import triples (one per repo: settings + 2 rulesets). @@ -16,9 +17,11 @@ settings plus `protect-main` and `protect-tags` rulesets. ## Authentication -Run tofu with `GITHUB_TOKEN` exported in the shell; the GitHub provider -reads it from the environment. The token needs Administration: write on -every managed repository. +Run tofu with `GITHUB_TOKEN` exported in the shell, or via the mise tasks +`mise run tofu:plan` / `mise run tofu:apply`, which inject the organization +token from 1Password. The token needs Administration: write on every managed +repository. It also needs org admin on `jackin-project` for the organization +settings and Actions policies in `organization.tf`. ## Adding a repository @@ -32,6 +35,13 @@ every managed repository. 2. Add one import triple (settings + `protect_main` + `protect_tags`) to `imports.tf` using the live numeric ruleset IDs. +## Organization overlays + +- `organization.tf` manages the org profile (`github_organization_settings`), + Actions availability/allow policy (`github_actions_organization_permissions`), + and default `GITHUB_TOKEN` workflow permissions + (`github_actions_organization_workflow_permissions`). + ## Verification ```sh diff --git a/imports.tf b/imports.tf index cd3e060..2a039ec 100644 --- a/imports.tf +++ b/imports.tf @@ -4,6 +4,21 @@ # Adopt the existing GitHub resources into the default local state before managing them. # These stable IDs prevent a fresh state from planning duplicate repositories or rulesets. +import { + to = github_organization_settings.jackin_project + id = "273541039" +} + +import { + to = github_actions_organization_permissions.jackin_project + id = "jackin-project" +} + +import { + to = github_actions_organization_workflow_permissions.jackin_project + id = "jackin-project" +} + import { to = module.repository_policy.github_repository.managed_settings["homebrew-tap"] id = "homebrew-tap" diff --git a/mise.toml b/mise.toml index bb6e558..5d5900d 100644 --- a/mise.toml +++ b/mise.toml @@ -9,3 +9,25 @@ opentofu = "1.13.1" python = "3.14" uv = "0.11.29" "pipx:reuse" = { version = "6.2.0", extras = "charset-normalizer", depends = ["python"] } + +[tasks."tofu:plan"] +description = "Run tofu plan" +run = """ +set -eu +export OP_ACCOUNT='zhokhov.1password.com' +GITHUB_TOKEN="$(op read 'op://Private/hq3g4pvryg4iise4vxwhk6p5jy/jackin-project-opentofu')" || { echo "op read failed, refusing to run" >&2; exit 1; } +export GITHUB_TOKEN +[ -n "${GITHUB_TOKEN:-}" ] || { echo "GITHUB_TOKEN is empty, refusing to run" >&2; exit 1; } +exec tofu plan "$@" +""" + +[tasks."tofu:apply"] +description = "Run tofu apply" +run = """ +set -eu +export OP_ACCOUNT='zhokhov.1password.com' +GITHUB_TOKEN="$(op read 'op://Private/hq3g4pvryg4iise4vxwhk6p5jy/jackin-project-opentofu')" || { echo "op read failed, refusing to run" >&2; exit 1; } +export GITHUB_TOKEN +[ -n "${GITHUB_TOKEN:-}" ] || { echo "GITHUB_TOKEN is empty, refusing to run" >&2; exit 1; } +exec tofu apply "$@" +""" diff --git a/organization.tf b/organization.tf new file mode 100644 index 0000000..47786e1 --- /dev/null +++ b/organization.tf @@ -0,0 +1,50 @@ +# SPDX-FileCopyrightText: 2026 Alexey Zhokhov +# SPDX-License-Identifier: Apache-2.0 + +# Organization-wide policy. Actions permissions and workflow defaults match the +# live baseline (tightening waits for per-repo workflow audits). New-repository +# security defaults are intentionally hardened (detection-only, future repos). + +resource "github_organization_settings" "jackin_project" { + billing_email = "alexey@zhokhov.com" + + name = "" + description = "" + blog = "" + email = "jackin@tailrocks.com" + location = "Singapore" + + has_organization_projects = true + has_repository_projects = true + default_repository_permission = "read" + members_can_create_repositories = true + + members_can_create_public_repositories = true + members_can_create_private_repositories = true + + members_can_create_pages = true + members_can_create_public_pages = true + members_can_create_private_pages = true + + members_can_fork_private_repositories = false + web_commit_signoff_required = false + + dependabot_alerts_enabled_for_new_repositories = true + dependabot_security_updates_enabled_for_new_repositories = true + dependency_graph_enabled_for_new_repositories = true + secret_scanning_enabled_for_new_repositories = true + secret_scanning_push_protection_enabled_for_new_repositories = true +} + +resource "github_actions_organization_permissions" "jackin_project" { + enabled_repositories = "all" + allowed_actions = "all" + sha_pinning_required = false +} + +resource "github_actions_organization_workflow_permissions" "jackin_project" { + organization_slug = var.github_organization + + default_workflow_permissions = "write" + can_approve_pull_request_reviews = false +} diff --git a/outputs.tf b/outputs.tf index 15b6a23..48bc517 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,6 +1,10 @@ # SPDX-FileCopyrightText: 2026 Alexey Zhokhov # SPDX-License-Identifier: Apache-2.0 +output "organization" { + value = var.github_organization +} + output "managed_repositories" { description = "Set of managed repository names (inventory keys)" value = module.repository_policy.managed_repositories From 8c9741f0bb72d9dbf49a375080b59e7def845a33 Mon Sep 17 00:00:00 2001 From: Alexey Zhokhov Date: Mon, 12 Oct 2026 18:36:55 +0700 Subject: [PATCH 4/4] docs: make mandatory-list update unconditional in runbook Codex PR feedback: the previous wording tied the checks.tf mandatory-list update to the no-CI clause, but mandatory_target_repositories_present compares the full key set, so every addition needs it. Signed-off-by: Alexey Zhokhov --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2e062f1..f6341d1 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ settings and Actions policies in `organization.tf`. list from `locals.tf` (`standard` = `["Required", "DCO"]`, `policy` = `["Policy"]`); bespoke checks inline with a comment citing the producing workflow. Repos with no CI use `required_checks = []` plus a non-empty - `no_ci_reason`, extend the allowlist check in `checks.tf`, and add the - name to the mandatory list in `mandatory_target_repositories_present` in - `checks.tf` (updating its count and message). + `no_ci_reason` and extend the allowlist check in `checks.tf`. Always add + the name to the mandatory list in `mandatory_target_repositories_present` + in `checks.tf` (updating its count and message). 2. Add one import triple (settings + `protect_main` + `protect_tags`) to `imports.tf` using the live numeric ruleset IDs.