Created
October 3, 2017 16:45
-
-
Save denniswebb/45703f8cdcddfb96c7268bb60ebd5842 to your computer and use it in GitHub Desktop.
Terraform module for creating GitHub repositories.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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