Skip to content

[BUG]: Sporadic visibility update error on repo creation #2700

Description

@nbarber-macu

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

Activity

  1. added
    Type: Bug
    Status: Triage
    on Jul 10, 2025
  2. Ankvi commented on Aug 13, 2025

    @Ankvi

    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

  3. moved this from Backlog to In Progress in Terraform Provideron Jan 7, 2026
  4. deiga commented on Jul 3, 2026

    @deiga
    Collaborator

    @Ankvi would you be able to reproduce this on the latest provider version? There have been many improvements made since this issue was opened

  5. changed the title [-][BUG]:[/-] [+][BUG]: Sporadic visibility update error on repo creation[/+] on Jul 3, 2026
  6. linked a pull request that will close this issue[MAINT] Modernize `github_repository` resource #3310on Jul 22, 2026
  7. added theissue type on Jul 22, 2026
  8. self-assigned this
    on Jul 22, 2026
  9. added this to the v6.14.0 milestone on Jul 22, 2026
  10. audunsolemdal commented on Sep 3, 2026

    @audunsolemdal

    @Ankvi would you be able to reproduce this on the latest provider version? There have been many improvements made since this issue was opened

    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.

  11. NGhafoor commented on Sep 30, 2026

    @NGhafoor

    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

  12. deiga commented on Sep 30, 2026

    @deiga
    Collaborator

    @NGhafoor thank you for the detailed write-up! We are well aware of the problematic mechanics here 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Awaiting responseStatus: TriageType: Bugr/repository

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions