Skip to content

Instantly share code, notes, and snippets.

@denniswebb
Created October 3, 2017 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denniswebb/45703f8cdcddfb96c7268bb60ebd5842 to your computer and use it in GitHub Desktop.
Save denniswebb/45703f8cdcddfb96c7268bb60ebd5842 to your computer and use it in GitHub Desktop.
Terraform module for creating GitHub repositories.
variable "repository_name" {}
variable "auto_init" {
default = true
}
variable "description" {
default = ""
}
variable "private" {
default = false
}
variable "has_downloads" {
default = true
}
variable "has_issues" {
default = true
}
variable "has_wiki" {
default = true
}
variable "branches_to_protect" {
type = "list"
default = ["master"]
}
variable "required_status_checks" {
type = "list"
default = ["circleci"]
}
resource "github_repository" "main" {
name = "${var.repository_name}"
description = "${var.description}"
private = "${var.private}"
has_downloads = "${var.has_downloads}"
has_issues = "${var.has_issues}"
has_wiki = "${var.has_wiki}"
auto_init = "${var.auto_init}"
lifecycle {
prevent_destroy = true
}
}
resource "github_branch_protection" "main" {
count = "${length(var.branches_to_protect)}"
repository = "${github_repository.main.name}"
branch = "${var.branches_to_protect[count.index]}"
enforce_admins = true
required_status_checks {
contexts = ["${var.required_status_checks}"]
}
required_pull_request_reviews {
dismiss_stale_reviews = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment