Skip to content

Instantly share code, notes, and snippets.

@soerenmartius
Last active March 8, 2020 12:10
Show Gist options
  • Save soerenmartius/2a5a691e653fe2b8d8abc01c46112578 to your computer and use it in GitHub Desktop.
Save soerenmartius/2a5a691e653fe2b8d8abc01c46112578 to your computer and use it in GitHub Desktop.
How to manage your GitHub Organization with Terraform - without modules
provider github {
organization = var.organization
}
# Make the organization configurable through variables
variable "organization" {
description = "The name of the organization to deploy the resources in."
type = string
}
# Add a user to the organization
resource "github_membership" "member" {
username = "a-github-user"
role = "member"
}
# Add a repository
resource "github_repository" "repository" {
name = "a-test-repository"
description = "This repository only exists for testing purposes."
private = false
allow_merge_commit = true
allow_rebase_merge = false
allow_squash_merge = false
auto_init = true
gitignore_template = "Terraform"
license_template = "mit"
}
# Configure a branch protection for the repository
resource "github_branch_protection" "repository" {
repository = github_repository.repository.name
branch = "master"
enforce_admins = true
required_status_checks {
strict = false
contexts = ["ci/travis"]
}
required_pull_request_reviews {
dismiss_stale_reviews = true
dismissal_users = [github_membership.member.username]
}
restrictions {
users = [github_membership.member.username]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment