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.

Related Blog Posts
Building Better Data Visualization Experiences: Part 1 of 2
Through direct experience with data scientists, business analysts, lab technicians, as well as other UX professionals, I have found that we need a better understanding of the people who will be using our data visualization products in order to build them. Creating a product utilizing data with the goal of providing insight is fundamentally different from a typical user-centric web experience, although traditional UX process methods can help.
Kafka Schema Evolution With Java Spring Boot and Protobuf
In this blog I will be demonstrating Kafka schema evolution with Java, Spring Boot and Protobuf.  This app is for tutorial purposes, so there will be instances where a refactor could happen. I tried to […]
Redis Bitmaps: Storing state in small places
Redis is a popular open source in-memory data store that supports all kinds of abstract data structures. In this post and in an accompanying example Java project, I am going to explore two great use […]
Let’s build a WordPress & Kernel updated AMI with Packer
First, let’s start with What is an AMI? An Amazon Machine Image (AMI) is a master image for the creation of virtual servers in an AWS environment. The machine images are like templates that are configured with […]