<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Github on zharif.my</title>
        <link>https://zharif.my/tags/github/</link>
        <description>Recent content in Github on zharif.my</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-us</language>
        <lastBuildDate>Wed, 22 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://zharif.my/tags/github/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>GitHub Organization as Code with Terraform</title>
        <link>https://zharif.my/posts/github-management-plane/</link>
        <pubDate>Wed, 22 Apr 2026 00:00:00 +0000</pubDate>
        
        <guid>https://zharif.my/posts/github-management-plane/</guid>
        <description>&lt;img src="https://images.unsplash.com/photo-1556075798-4825dfaaf498?w=800&amp;h=400&amp;fit=crop" alt="Featured image of post GitHub Organization as Code with Terraform" /&gt;&lt;h2 id=&#34;why-this-matters&#34;&gt;Why This Matters
&lt;/h2&gt;&lt;p&gt;If you&amp;rsquo;ve ever tried to explain to your team that &amp;ldquo;we can&amp;rsquo;t create a new repo right now, I&amp;rsquo;m at dinner,&amp;rdquo; you understand why GitHub management should be code. Every infrastructure change in my homelab goes through code review — including how we manage GitHub itself.&lt;/p&gt;
&lt;p&gt;The problem: GitHub&amp;rsquo;s web UI is fine for 3 repos, painful for 30+. You can&amp;rsquo;t track who changed what, can&amp;rsquo;t enforce naming conventions, and can&amp;rsquo;t ensure consistency across repositories.&lt;/p&gt;
&lt;p&gt;The solution: treat your GitHub organization like database infrastructure. Define everything in YAML, let Terraform handle the drift, and sleep better at night.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Scale&lt;/strong&gt;: This setup manages 40+ repositories across my organization with full configuration, teams, secrets, and custom properties.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;All Terraform resources support &lt;code&gt;lifecycle { create_before_destroy = true }&lt;/code&gt; for zero-downtime deployments.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;architecture&#34;&gt;Architecture
&lt;/h2&gt;&lt;p&gt;The &lt;code&gt;github-management-plane&lt;/code&gt; repository manages my GitHub organization through Terraform — the same configuration-driven pattern as my homelab infrastructure:&lt;/p&gt;
&lt;pre class=&#34;mermaid&#34;&gt;
  graph TB
    G[github-management-plane]
    R[Repository Module]
    S[Secrets/Variables Module]
    O[Organization Custom Properties]
    
    G --&amp;gt; R
    G --&amp;gt; S
    G --&amp;gt; O
    
    Repos[&amp;#34;All Repositories&amp;#34;]
    Vars[&amp;#34;Actions Variables&amp;#34;]
    Secs[&amp;#34;Actions Secrets&amp;#34;]
    
    Repos --&amp;gt; tf-infra-homelab[&amp;#34;tf-infra-homelab&amp;#34;]
    Repos --&amp;gt; tf-module-proxmox-talos[&amp;#34;tf-module-proxmox-talos&amp;#34;]
    Repos --&amp;gt; applications-homelab[&amp;#34;applications-homelab&amp;#34;]
    Repos --&amp;gt; ...[&amp;#34;24+ repositories&amp;#34;]
&lt;/pre&gt;

&lt;h2 id=&#34;what-this-module-does&#34;&gt;What This Module Does
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Repository management&lt;/strong&gt; — create and configure all repositories via YAML&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Team management&lt;/strong&gt; — define teams and members&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Organization custom properties&lt;/strong&gt; — classify repositories&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Actions secrets/variables&lt;/strong&gt; — manage organization-wide secrets&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Issue labels&lt;/strong&gt; — standardize labels across repositories&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;quick-start&#34;&gt;Quick Start
&lt;/h2&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;module &amp;#34;repositories&amp;#34; {
  source   = &amp;#34;./modules/repository&amp;#34;
  for_each = local.filtered_repo_configurations
  
  configuration = each.value
  organization  = var.github_organization
}&lt;/code&gt;&lt;/pre&gt;&lt;hr&gt;
&lt;h2 id=&#34;repository-management&#34;&gt;Repository Management
&lt;/h2&gt;&lt;p&gt;All repositories are defined as YAML configurations:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;# configurations/repository/tf-infra-homelab.yaml
name: tf-infra-homelab
description: A terraform infrastructure repository for managing my homelab environment
enabled: true
archived: false
visibility: private
type: terraform-infrastructure

topics:
  - homelab
  - proxmox

enabled_features:
  vulnerability_alerts: true
  issues: true
  wiki: false
  projects: false
  discussions: false&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;repository-types&#34;&gt;Repository Types
&lt;/h3&gt;&lt;p&gt;The module supports different repository types with defaults:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;locals {
  repository_types = {
    terraform-infrastructure = {
      license_template = &amp;#34;mit&amp;#34;
      auto_init       = true
      topics        = [&amp;#34;terraform&amp;#34;, &amp;#34;homelab&amp;#34;]
    }
    terraform-module = {
      license_template = &amp;#34;mit&amp;#34;
      auto_init       = true
      topics         = [&amp;#34;terraform&amp;#34;, &amp;#34;proxmox&amp;#34;]
    }
    python-docker-application = {
      license_template = &amp;#34;mit&amp;#34;
      auto_init       = true
      topics         = [&amp;#34;python&amp;#34;, &amp;#34;docker&amp;#34;]
    }
    generic = {
      auto_init = true
    }
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;repository-resource&#34;&gt;Repository Resource
&lt;/h3&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;github_repository&amp;#34; &amp;#34;this&amp;#34; {
  name        = var.configuration.name
  description = var.configuration.description
  visibility  = var.configuration.visibility
  
  allow_rebase_merge    = true
  allow_squash_merge  = true
  delete_branch_on_merge = true
  
  vulnerability_alerts = var.configuration.enabled_features.vulnerability_alerts
  has_discussions     = var.configuration.enabled_features.discussions
  has_issues         = var.configuration.enabled_features.issues
  has_projects       = var.configuration.enabled_features.projects
  has_wiki           = var.configuration.enabled_features.wiki
}&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;organization-custom-properties&#34;&gt;Organization Custom Properties
&lt;/h2&gt;&lt;p&gt;Custom properties allow classification and filtering:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;locals {
  organization_custom_properties = {
    &amp;#34;can-be-public&amp;#34; = {
      description   = &amp;#34;To indicate whether the repository can be made public&amp;#34;
      value_type  = &amp;#34;single_select&amp;#34;
      required   = true
      allowed_values = [&amp;#34;true&amp;#34;, &amp;#34;false&amp;#34;]
      default_value = &amp;#34;false&amp;#34;
    }
    
    &amp;#34;managed-by&amp;#34; = {
      description = &amp;#34;To identify who manages the repository&amp;#34;
      value_type = &amp;#34;single_select&amp;#34;
      required = true
      allowed_values = [
        &amp;#34;github-management-plane&amp;#34;,
        &amp;#34;manual-management&amp;#34;,
      ]
      default_value = &amp;#34;manual-management&amp;#34;
    }
    
    &amp;#34;repository-type&amp;#34; = {
      description = &amp;#34;To indicate the type of repository&amp;#34;
      value_type = &amp;#34;single_select&amp;#34;
      required = true
      allowed_values = [
        &amp;#34;generic&amp;#34;,
        &amp;#34;repository-template&amp;#34;,
        &amp;#34;golang-linux-package&amp;#34;,
        &amp;#34;golang-docker-application&amp;#34;,
        &amp;#34;python-docker-application&amp;#34;,
        &amp;#34;python-package&amp;#34;,
        &amp;#34;terraform-infrastructure&amp;#34;,
        &amp;#34;terraform-module&amp;#34;,
      ]
    }
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Apply them:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;github_organization_custom_properties&amp;#34; &amp;#34;managed_properties&amp;#34; {
  for_each   = local.organization_custom_properties
  
  property_name = each.key
  value_type  = each.value.value_type
  required   = each.value.required
  description = each.value.description
  default_value = each.value.default_value
  allowed_values = each.value.allowed_values
}&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;secrets-and-variables&#34;&gt;Secrets and Variables
&lt;/h2&gt;&lt;p&gt;Actions secrets and variables are managed through Bitwarden:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;# configurations/secrets_variables/global.yaml
variables:
  - name: RUNNER
    value: self-hosted
    visibility: all

secrets:
  - name: BWS_ACCESS_TOKEN
    is_manual: true
    visibility: private&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;variable-resource&#34;&gt;Variable Resource
&lt;/h3&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;github_actions_organization_variable&amp;#34; &amp;#34;managed_variables&amp;#34; {
  for_each = { for v in var.configuration.variables : v.name =&amp;gt; v }
  
  variable_name = each.value.name
  visibility   = each.value.visibility
  value        = each.value.value
}&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;secret-resource&#34;&gt;Secret Resource
&lt;/h3&gt;&lt;p&gt;For secrets, two patterns:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;# Manual secrets (value set outside Terraform)
resource &amp;#34;github_actions_organization_secret&amp;#34; &amp;#34;managed_secrets_manual&amp;#34; {
  for_each = { for v in var.configuration.secrets : v.name =&amp;gt; v if v.is_manual }
  
  secret_name = each.value.name
  visibility = each.value.visibility
  plaintext_value = &amp;#34;NONE&amp;#34;
}

# Synced secrets (from Bitwarden)
resource &amp;#34;github_actions_organization_secret&amp;#34; &amp;#34;managed_secrets_sync&amp;#34; {
  for_each = { for v in var.configuration.secrets : v.name =&amp;gt; v if !v.is_manual }
  
  secret_name     = each.value.name
  visibility     = each.value.visibility
  plaintext_value = data.bitwarden-secrets_secret.secrets[each.value.name].value
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Get secrets from Bitwarden:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;data &amp;#34;bitwarden-secrets_secret&amp;#34; &amp;#34;secrets&amp;#34; {
  for_each = { for v in local.all_secrets : v.name =&amp;gt; v if !v.is_manual }
  id      = each.value.bw_secret_id
}&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;team-management&#34;&gt;Team Management
&lt;/h2&gt;&lt;p&gt;Teams are defined in the main module:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;github_team&amp;#34; &amp;#34;organization_administrators&amp;#34; {
  name        = &amp;#34;organization-administrators&amp;#34;
  description = &amp;#34;Team with administrative access to the organization&amp;#34;
  privacy     = &amp;#34;closed&amp;#34;
}

resource &amp;#34;github_team_members&amp;#34; &amp;#34;organization_administrators_members&amp;#34; {
  team_id = github_team.organization_administrators.id
  
  members = {
    &amp;#34;your-username&amp;#34; = {
      role = &amp;#34;maintainer&amp;#34;
    }
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;issue-labels&#34;&gt;Issue Labels
&lt;/h2&gt;&lt;p&gt;Labels are standardized across repositories:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;locals {
  shared_labels = {
    &amp;#34;bug&amp;#34; = {
      color   = &amp;#34;d73a4a&amp;#34;
      description = &amp;#34;Bug report&amp;#34;
    }
    &amp;#34;enhancement&amp;#34; = {
      color   = &amp;#34;a2eeef&amp;#34;
      description = &amp;#34;New feature&amp;#34;
    }
    &amp;#34;documentation&amp;#34; = {
      color   = &amp;#34;0075ca&amp;#34;
      description = &amp;#34;Documentation improvements&amp;#34;
    }
  }
}

resource &amp;#34;github_issue_labels&amp;#34; &amp;#34;this&amp;#34; {
  repository = var.configuration.name
  
  label = merge(
    local.shared_labels,
    try(var.configuration.labels, {})
  )
}&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;my-repository-configuration&#34;&gt;My Repository Configuration
&lt;/h2&gt;&lt;p&gt;Here&amp;rsquo;s the list of repositories managed:&lt;/p&gt;
&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-txt&#34;&gt;configurations/repository/
├── tf-infra-homelab.yaml          # Homelab infrastructure
├── tf-infra-github-management-plane.yaml  # GitHub management
├── tf-module-proxmox-lxc.yaml    # LXC module
├── tf-module-proxmox-vm.yaml    # VM module
├── tf-module-proxmox-talos.yaml  # Talos module
├── tf-module-proxmox-docker.yaml # Docker module
├── applications-homelab.yaml   # Kustomize apps
├── cf-worker-terraform-registry.yaml  # TF registry worker
├── cf-worker-apt-repository.yaml   # APT repository worker
├── template-terraform-basic.yaml   # Module template
├── template-cloudflare-worker-python.yaml  # Worker template
└── ... (24 total)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each is just a YAML file — adding a new repository is adding a file.&lt;/p&gt;
&lt;h2 id=&#34;configuration-structure&#34;&gt;Configuration Structure
&lt;/h2&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-txt&#34;&gt;github-management-plane/
├── configurations/
│   ├── repository/           # Repository definitions
│   ├── secrets_variables/   # Actions secrets/variables
│   └── rulesets/           # Branch protection (future)
├── modules/
│   ├── repository/         # Repository module
│   ├── secrets_variables/  # Secrets module
│   └── organization/        # Org properties module
├── main.tf                 # Orchestration
├── locals.tf              # Configuration loading
└── providers.tf          # Provider setup&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This mirrors the homelab infrastructure structure.&lt;/p&gt;
&lt;h2 id=&#34;outputs&#34;&gt;Outputs
&lt;/h2&gt;&lt;p&gt;The module doesn&amp;rsquo;t have specific outputs since it manages the organization passively.&lt;/p&gt;
&lt;h2 id=&#34;whats-next&#34;&gt;What&amp;rsquo;s Next
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Branch protection rulesets&lt;/strong&gt; — via rulesets API (when Terraform provider supports it)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Repository invitations&lt;/strong&gt; — managing outside collaborators&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security advisories&lt;/strong&gt; — automated security scanning&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;what-most-people-get-wrong&#34;&gt;What Most People Get Wrong
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&amp;ldquo;GitHub Terraform is just for repos&amp;rdquo;&lt;/strong&gt; — It&amp;rsquo;s org-wide: teams, custom properties, secrets, variables. The whole thing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&amp;ldquo;One Terraform run is enough&amp;rdquo;&lt;/strong&gt; — Git rate limits apply. Use &lt;code&gt;ratenode&lt;/code&gt; provider or caching.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&amp;ldquo;Manual changes are fine if you revert&amp;rdquo;&lt;/strong&gt; — Terraform drift will catch you. Enable &lt;code&gt;logento&lt;/code&gt; or run &lt;code&gt;terraform refresh&lt;/code&gt; regularly.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;when-to-use--when-not-to-use&#34;&gt;When to Use / When NOT to Use
&lt;/h2&gt;&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Use GitHub Management Plane&lt;/th&gt;
          &lt;th&gt;Do it manually&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;20+ repositories&lt;/td&gt;
          &lt;td&gt;1-5 repos&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Team collaboration&lt;/td&gt;
          &lt;td&gt;Personal projects&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Audit requirements&lt;/td&gt;
          &lt;td&gt;Quick experiments&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Secret/variable management&lt;/td&gt;
          &lt;td&gt;Ad-hoc scripts only&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This makes GitHub management declarative — every change goes through code review.&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
