Repository navigation
Closed
Labels
Status: PinnedA way to keep old or long lived issues aroundType: BugSomething isn't working as documentedr/branch_protection
Description
Terraform Version
0.12.6
Affected Resource(s)
Please list the resources as a list, for example:
github_repositorygithub_branch_protectiongithub_team_repositorygithub_actions_secret
Terraform Configuration Files
Here's our repo module (slightly redacted ****):
terraform {
required_providers {
github = ">= 3.1.0"
}
}
locals {
# Terraform modules must be named `terraform-<provider>-<module name>`
# so we can extract the provider easily
provider = element(split("-", var.repository), 1)
}
data "github_team" "****" {
slug = "****"
}
data "github_team" "****" {
slug = "****"
}
resource "github_repository" "main" {
name = var.repository
description = var.description
visibility = var.visibility
topics = [
"terraform",
"terraform-module",
"terraform-${local.provider}"
]
has_issues = var.has_issues
has_projects = var.has_projects
has_wiki = var.has_wiki
vulnerability_alerts = true
delete_branch_on_merge = true
archived = var.archived
dynamic "template" {
for_each = var.fork ? [] : [var.fork]
content {
owner = "waveaccounting"
repository = "****"
}
}
}
resource "github_branch_protection" "main" {
repository_id = github_repository.main.node_id
pattern = github_repository.main.default_branch
required_status_checks {
strict = true
contexts = [
"Terraform",
"docs",
]
}
required_pull_request_reviews {
dismiss_stale_reviews = true
require_code_owner_reviews = true
}
}
resource "github_team_repository" "****" {
team_id = data.github_team.****.id
repository = github_repository.main.name
permission = "admin"
}
resource "github_team_repository" "****" {
team_id = data.github_team.****.id
repository = github_repository.main.name
permission = "admin"
}
resource "github_actions_secret" "secrets" {
for_each = var.secrets
repository = github_repository.main.name
secret_name = each.key
plaintext_value = each.value
}
Actual Behavior
We are managing approximately 90 repositories using this module via Terraform Cloud remote operations (which means we can't disable refresh or change parallelization afaik). I timed a refresh + plan: 9m22s (562s) == 6.2s per repository
Are there any optimizations we can make on our side or in the github provider / API to try to improve this? We're discussing breaking up our repos into smaller workspaces, but that feels like a bit of a hack.
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform planon large numbers of repositories / branch protection configs
Important Factoids
- Running on Terraform Cloud Remote Operation
References
- Similar issue to https://github.com/terraform-providers/terraform-provider-github/issues/565, although things weren't particularly fast before the update either
Reacted by April Baird, Ahmad Nassri, Kyle Christensen, Kurt McAlpine, André Wendt, Stein Welberg, Brian Fox, Avner Cohen, Camilo Roca, Stan Domula and 83 more
Reacted by MichalMaciaszekOpensignal and Mateusz Kostyła
Metadata
Metadata
Assignees
Labels
Status: PinnedA way to keep old or long lived issues aroundType: BugSomething isn't working as documentedr/branch_protection
Type
Projects
- StatusShow more project fieldsDone
Activity
ahmadnassri commentedon Oct 17, 2020
this is also true for
v3.0.0, and has effectively rendered this provider unsable atv3.xwith more than 5 repos while managing files, labels, and permissions of each repo...reverting back to
2.9.2until this is resolvedjcudit commentedon Oct 19, 2020
Thanks for reporting this and providing the example config as well as timing measurements. 🙇
We can start with bringing this number down. Not sure how yet, but after some reading for https://github.com/terraform-providers/terraform-provider-github/issues/565, we may be able to collapse a few requests into one with GraphQL 🤔 .
jcudit commentedon Oct 20, 2020
Took a quick pass at this using the following generated test file:
The test was able to refresh 100 repos in 12s:
details
I don't doubt things are slow for your setup, however I'd like more information to better reproduce this.
@mwarkentin (or anyone else following) can I get counts of each of the resources?
terraform state list | cut -d. -f1 | uniq -cor similar would help!ahmadnassri commentedon Oct 20, 2020
@jcudit
github_branch_protectionandgithub_repository_fileis where I've seen the massive speed and rate limit issuesjcudit commentedon Oct 20, 2020
Thanks for confirming. Adding
github_branch_protectionto the test above reveals this poor performance.Will focus efforts there and will track
github_repository_filein https://github.com/terraform-providers/terraform-provider-github/issues/568 🙇mwarkentin commentedon Oct 20, 2020
@jcudit if it's still helpful:
jcudit commentedon Oct 22, 2020
Performed a round of measurements that compared
v3.1.0andv2.9.2(GraphQL vs. REST implementations). Some observations below:v3.1.0
v2.9.2
jcudit commentedon Oct 22, 2020
Given the results above, here are some recommendations:
github_branch_protectionback to the REST implementation, but handle unsupported configurations with the GraphQL implementationgithub_branch_protectionback to the REST implementation, forfeiting the features available via the GraphQL implementationI will attempt to get the first option into the upcoming bugfix release.
The second option is larger than I have time for but welcome PRs from contributors.
The last two options will need feedback / sign-off from the community. Interested to hear more opinions here if the first two options do not play out well.
current query
{ "query": "query($id:ID!){node(id: $id){... on BranchProtectionRule{repository{id,name},pushAllowances(first: 100){nodes{actor{... on Team{id,name},... on User{id,name}}}},reviewDismissalAllowances(first: 100){nodes{actor{... on Team{id,name},... on User{id,name}}}},dismissesStaleReviews,id,isAdminEnforced,pattern,requiredApprovingReviewCount,requiredStatusCheckContexts,requiresApprovingReviews,requiresCodeOwnerReviews,requiresCommitSignatures,requiresStatusChecks,requiresStrictStatusChecks,restrictsPushes,restrictsReviewDismissals}}}", "variables": { "id": "MDIwOkJyYW5jaFByb3RlY3Rpb25SdWxlMTgwMjU3Njc=" } }jspiro commentedon Nov 12, 2020
+1 – thanks to everyone taking this issue seriously. We also manage 55 repos, and I was hoping to one day manage about 400, but this has slowed us down too much to consider upgrading past 2.9.2.
FWIW a targeted plan of a single repo resources and with five branch protections, WITHOUT refresh and WITHOUT lock, took 15 seconds of real time:
I'd love for graphql to cut the thousands and thousands of REST calls we do per plan down, but not for such an increase in time. I suspect some of this work may be moot/pre-optimization given the refresh improvements in 0.14.0 (as I understand them)–perhaps we could go back to REST entirely for these calls until the issues are sorted?
A full plan without refresh and lock took:
And a full plan with refresh and lock:
For comparison, a full plan with refresh and lock in 2.9.2:
So on my machine, 3.0+ is 42% slower in a big plan, and in my testing, 300% slower in a single repo with five branches to protect. For reference, I'm on a 2019 MacBook Pro, maxed out, on a 75MB symmetric connection.
44 remaining items
fatbasstard commentedon Jul 10, 2025
This seems like a really nice improve that we'd like. Well, basically need.
orangewolf commentedon Jul 18, 2025
For those looking to get this speed bump until a merge can be done:
required_providers { github = { - source = "integrations/github" + source = "TES-Software/github" version = "~> 6.0" } }parallel_requeststo trueprovider "github" { owner = "YOUROWNER" + parallel_requests = true }You don't have to set
-parallelism=30on the command line. You can if you want, but it will get you a 10x speed bump even without increasing that.SamuZad commentedon Jul 30, 2025
I put up the PR for the change. It would be good to get a
yes, this sounds reasonableor ano we won't do thisfrom the team in the near futureUpdate priority list: mark completed issues
pickgr commentedon Sep 17, 2025
@orangewolf I'd recommend using the following fork (we have also switched to it):
https://registry.terraform.io/providers/nexthink-oss/github
They've modernized the provider and also fixed several issues in the "verified" provider which unfortunately seems to be abandoned by GitHub :(
dannysauer commentedon Oct 14, 2025
...Considering the only two commits in the past 8 months have been README updates to clarify exactly how much GitHub does not support this provider. 🤣