Managing Your Github Org with Terraform

With the increasing prevalence of highly distributed systems, it’s becoming very important to automate and template everything possible so your teams don’t get bogged down with mundane tasks. With so many moving parts between teams, projects, and infrastructure, manual tasks for each become error-prone and a source of bottlenecks. Hashicorp’s Terraform is a great tool that allows you to template and manage your infrastructure across all your different providers, and with it’s 0.6.14 release, you can now also manage your Github organizations.

Why Manage a Github Organization

Anyone that has been part of an organization with many moving teams, members, and projects knows that managing it can become frustrating. Anyone that gets stuck as the gatekeeper has to spend a fair amount of time clicking around in Github and you end up with teams and users that have keys to most of the kingdom because you don’t want to deal with such fine-grained control while you’re trying to get your interesting work done. Using Terraform’s Github provider and pull requests as the approval process greatly alleviates these issues.

Tutorial

This tutorial assumes you have installed and have basic knowledge of Terraform (both very easy using the getting started guide).

We’ll start by setting up the Github provider and a simple organization that will use all available resources. If you are following along you will have to create a Github organization, test user, and repository.

After setting the GITHUB_TOKEN and GITHUB_ORGANIZATION environment variables and plugging in your own user and repository, execute:

terraform plan

If the execution plan output doesn’t have any issues, you are ready to make these changes to your Github organization. execute:

terraform apply

If you go to Github, it should mirror your github.tf file. From now on adding/removing users, teams, users to those teams, repositories to those teams, or changing permissions is as easy as editing the file and applying.

Suggested Usage

If a single person is tasked with maintaining this file for each organizational change, this won’t be much of an improvement. Committing your Terraform files to Github and allowing a fork/pull model will allow everyone in the organization to own their own changes, but still give a select few the chance to quickly review them and approve just by clicking “merge”. This strikes a nice balance between offloading organizational maintenance work while not surrendering control.

NOTE:This setup is most effective with a build server that applies the Terraform changes after successful build, but that’s a post for another time.

About the Author

Object Partners profile.
Leave a Reply

Your email address will not be published. Required fields are marked *

Related Blog Posts
Getting Started with CSS Container Queries
For as long as I’ve been working full-time on the front-end, I’ve heard about the promise of container queries and their potential to solve the majority of our responsive web design needs. And, for as […]
Simple improvements to making decisions in teams
Software development teams need to make a lot of decisions. Functional requirements, non-functional requirements, user experience, API contracts, tech stack, architecture, database schemas, cloud providers, deployment strategy, test strategy, security, and the list goes on. […]
JavaScript Bundle Optimization – Polyfills
If you are lucky enough to only support a small subset of browsers (for example, you are targeting a controlled set of users), feel free to move along. However, if your website is open to […]
Creating Mocks For Unit Testing in Go
Unit testing is an important part of any project, and Go built its framework with a testing package; making unit testing part of the language. This testing framework is good for most scenarios, but you […]