Repository navigation
Description
Expected Behavior
Repo created and visibility changed to internal
Actual Behavior
The terraform apply action fails with a 422 Failed to update visibility. A previous repository operation is still in progress.
The issue is sporadic. Sometimes I can retry right away and it works on the second attempt. Other times it will fail 10 times in a row. I believe it's caused by a race condition with the GitHub API -- making the assumption that it's because the repository create operation isn't quite finished before the visibility update is attempted.
terraform apply -auto-approve \
-var "org=myorg" \
-var "repo=myrepo \
-var "repo_visibility=internal" \
-var "template=mytemplate" \
-var "team=myteam"
............
Plan: 30 to add, 0 to change, 0 to destroy.
github_repository.repo: Creating...
│ Error: PATCH https://api.github.com/repos/myorg/myrepo: 422 Failed to update visibility. A previous repository operation is still in progress. []
│
│ with github_repository.repo,
│ on repo.tf line 4, in resource "github_repository" "repo":
│ 4: resource "github_repository" "repo" {
│
╵
Error: Process completed with exit code 1.
Terraform Version
1.1.7
This is happening on our self-hosted github agents and without testing thoroughly, I don't want to break our 100s of other terraform workflows.
Affected Resource(s)
- github_repository
Terraform Configuration Files
locals {
template = toset([var.template])
}
resource "github_repository" "repo" {
name = var.repo
description = var.repo_desc
visibility = var.repo_visibility
auto_init = true
dynamic "template" {
for_each = local.template
content {
owner = var.org
repository = template.value
include_all_branches = true
}
}
}
resource "github_branch_default" "default" {
repository = github_repository.repo.name
branch = var.default_branch
}Steps to Reproduce
terraform apply -- see output above for full command. I can provide all the .tf files if necessary. Given that it happens on the very first step, I opted to not provide the other 6 .tf files
This is difficult to reproduce because it doesn't happen every time a repo creation happens.
Debug Output
Panic Output
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields🆕 Triage
- StatusShow more project fieldsIn Progress
Activity
Ankvi commentedon Aug 13, 2025
We're seeing the same issue. We create all of our repositories through templates. It seems like the GitHub REST API endpoint for creating a repo with templates started to return early instead of waiting for the repo to be initialized
deiga commentedon Jul 3, 2026
@Ankvi would you be able to reproduce this on the latest provider version? There have been many improvements made since this issue was opened
[-][BUG]:[/-][+][BUG]: Sporadic visibility update error on repo creation[/+]audunsolemdal commentedon Sep 3, 2026
I can confirm this happens regularly on provider version 6.13.0 and causes the repo to be tainted and recreated in an infinite loop unless it is manually untainted.
TF version 1.16.1, amd64.
NGhafoor commentedon Sep 30, 2026
We are also consistently reproducing this on integrations/github v6.13.0 when creating an internal repository from a template.
We raised this with GitHub Support, who investigated the server-side repository activity. They confirmed that each Terraform run creates the repository successfully, sends one repository update which succeeds, and then sends a second update approximately 1.3 seconds later, which receives:
422 Failed to update visibility. A previous repository operation is still in progress.
GitHub Support observed the same sequence across six repository IDs and confirmed there was no outstanding/stuck repository operation requiring clearance. The failed resource is then tainted, so the next apply deletes/recreates the repository and repeats the sequence.
GitHub Support recommended that the visibility change not be sent immediately after another repository settings update, or that the visibility update be retried with backoff after the previous operation has completed.
Configuration is github_repository with a template block and visibility = "internal".
Terraform: v1.52.2
GitHub provider: v6.13.0
deiga commentedon Sep 30, 2026
@NGhafoor thank you for the detailed write-up! We are well aware of the problematic mechanics here 🙏