Skip to content

Instantly share code, notes, and snippets.

@ksatirli
Created January 31, 2020 13:17
Show Gist options
  • Save ksatirli/a964565b6625899a91065b997e2be31f to your computer and use it in GitHub Desktop.
Save ksatirli/a964565b6625899a91065b997e2be31f to your computer and use it in GitHub Desktop.
Presentation Notes: Managing GitHub with Terraform

Managing GitHub with Terraform

More HashiCorp Content

resource "github_branch_protection" "monitoring-app" {
repository = github_repository.monitoring-app.name
branch = "master"
enforce_admins = true
require_signed_commits = true
required_status_checks {
strict = true
contexts = ["ci/enforcer"]
}
required_pull_request_reviews {
dismiss_stale_reviews = true
dismissal_teams = [github_team.reviewers.slug]
}
restrictions {
teams = [github_team.reviewers.slug]
}
}
resource "github_membership" "kibertoad" {
username = "kibertoad"
role = "member"
}
provider "github" {
token = "abc...890"
organization = "operatehappy"
version = "~> 2.3"
}
# remove the `monitoring-app` resource from Terraform's State
terraform state rm github_repository.monitoring-app
# import the `monitoring-app` resource into Terraform's State
terraform import github_repository.monitoring-app monitoring-app
resource "github_repository" "monitoring-app" {
name = "monitoring-app"
description = "Operate Happy's monitoring app"
homepage_url = "https://operatehappy.com/monitoring-app"
private = false
has_downloads = false
has_issues = true
has_projects = false
has_wiki = false
allow_merge_commit = false
allow_rebase_merge = false
allow_squash_merge = true
auto_init = false
template {
owner = "operatehappy"
repo = "terraform-module-template"
}
topics = [
"application",
"monitoring"
]
}
resource "github_team_membership" "reviewers" {
count = length(var.reviewer_team_members)
team_id = github_team.reviewers.id
username = element(var.reviewer_team_members, count.index)
role = "maintainer"
}
resource "github_team_repository" "monitoring-app" {
team_id = github_team.reviewers.id
repository = github_repository.monitoring-app.name
permission = "push"
}
resource "github_team" "reviewers" {
name = "reviewers"
description = "Reviewer Team"
privacy = "closed"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment