This repository automates the management of GitHub repositories within the G-Research GitHub organization using Terraform Cloud and GitHub Actions. It supports both the import of existing repositories and the provisioning of new repositories, ensuring GitHub configuration is reproducible, auditable, and version-controlled.
- 🛠️ Import existing GitHub repositories into Terraform Cloud state
- 📦 Provision new repositories using declarative YAML configurations
- 🤖 GitHub Actions workflows for automation and CI/CD
- 🔀 Supports both
devandprodenvironments - 👥 Support for multiple Github organizations
- 🧩 Manages metadata including:
- General repository settings
- Branch protection rules
- Default branch
- Teams and collaborators
- Repository rulesets
feature/
├── github-repo-importer/ # Logic for importing (reading settings) of existing GitHub repos
└── github-repo-provisioning/ # Terraform modules for managing GitHub repos
└── repo_configs/
├── dev/
│ ├── gr-oss-devops/ # gr-oss-devops organization repositories
│ └── gr-oss-developers/ # gr-oss-developers organization repositories
└── prod/
├── G-Research/ # G-Research organization repositories
└── armadaproject/ # armadaproject organization repositories
This project leverages Terraform Cloud (TFE) to manage GitHub repositories declaratively. Pull requests into the configuration directories trigger Terraform runs for plan and apply stages, aligning GitHub state with the YAML definitions.
To provision a brand-new repository in the G-Research GitHub organization:
- Create a pull request targeting the
feature/github-repo-provisioning/prod/{organisation}/directory - Add a YAML file describing the desired repository configuration - name of the YAML file will be the name of the repository (case-sensitive)
- Submit the PR for review
- Upon approval and merge, Terraform Cloud will:
- Plan and apply the configuration
- Create the repository
📝 New repositories must not be forks. Forks follow a different workflow (see below).
To import a forked repository into the organization:
- Trigger the Create fork workflow
- Provide input:
upstream_repo: Repo to fork (in the format ofowner/repo)fork_name: Name of the new forked repository. If left empty, default would be the same as the upstream repo namedefault_branch_only: To create the fork with only the default branch (e.g.,mainormaster) or all branches. Default istruefork_to_org: The organization to fork the repository into (e.g.,G-Researchorarmadaproject)
- Workflow will fork and import the repository triggering the import workflow. From here, the process is similar to importing an existing repository:
- The workflow will generate a YAML config for the forked repository
- Place it under
feature/github-repo-provisioning/importer_tmp_dir/{organization}/ - Create a PR against the
prodbranch - User reviews, approves, and merges the PR
- After merge Terraform Cloud will import the forked repository into its state by applying the generated YAML configuration
- The configuration file is then sanitized (ids removed) and moved to the appropriate directory
feature/github-repo-provisioning/repo_configs/{branch}/{organization} - From here, user can make changes to the configuration file as needed, and create a PR against the
feature/github-repo-provisioning/prod/{organisation}/{repository}.yamlfile to apply further changes
📝 We are working on improving this so that the user has the same experience as when creating a new repo
Important
All important attributes are documented in the Developer's Guide.