Reusable Terraform module that codifies a standard hardening posture for a GitHub repository: settings, branch/tag rulesets, a canonical label set, community/governance files, and shared CI workflows, every piece opt-in via a boolean.
Pin it by tag.
module "my_repo" {
source = "git::https://github.com/protocortex/terraform-github-security-repo.git?ref=v0.1.0"
name = "my-repo"
description = "…"
visibility = "private"
owner = "my-org"
maintainer = "my-github-handle"
security_contact_email = "security@example.com"
# private_free_tier is derived from visibility by default: the eight features
# GitHub 403s on a free-tier private repo (rulesets, vuln alerts, secret
# scanning + push protection, Dependabot security updates, dependency review,
# private vuln reporting) switch off automatically, and switch on when the
# repo goes public. Set it explicitly only on a paid plan.
# WARNING: manage_labels = true DELETES any label not in the canonical set.
manage_labels = false
}The provider is configured by the calling root, not here. Pass a github
provider (App auth or PAT) whose owner matches the repos being managed.
github_repository.thishasprevent_destroy = trueandarchive_on_destroy = true: Terraform refuses to destroy the repo and, in a forced override, archives rather than deletes.private_free_tierdrives acheckblock that fails the plan if a Pro-only feature is enabled on a private repo without it.
variables.tf is the full public API (~90 variables). The common groups:
- Identity,
name,owner(required),description,visibility,topics. - Free-tier / security,
private_free_tier,enable_*toggles. - Governance files,
manage_security_md,manage_code_of_conduct,manage_codeowners,manage_icla,manage_ccla,manage_license, … - Workflows, one
manage_workflow_*per shared workflow. - Workflow timeouts,
workflow_timeout_minutes(an object with one optional job timeout per managed workflow; set only the keys you want to change),workflow_harden_runner_timeout_minutes(default 5) andworkflow_osv_scanner_timeout_minutes(default 10). They stop a hung runner from holding a job for GitHub's 360 minute default. - Plan-time reads,
github_token(optional; only needed whenmanage_security_mdorenforce_pr_creation_policyis true, for private-repo REST reads).
Apache-2.0. See LICENSE.