Skip to content

[BUG]: 422 error: Race condition updating visibility to internal after template repo creation (no retry/backoff on PATCH) #3302

Closed as duplicate

Description

@milagrofrost

Expected Behavior

When creating a repository from a template with visibility = "internal", the operation should complete successfully without spurious 422 errors, and the desired visibility should be set reliably by Terraform. The provider should handle any normal GitHub-side settling delays internally (via retry/backoff) so users do not need to tune write_delay_ms or split operations across multiple applies.

Actual Behavior

Creating a repo from a template with visibility = "internal" frequently fails with:

Error: PATCH https://api.github.com/repos/[org]/[repo]: 422 Failed to update visibility. A previous repository operation is still in progress. []

This is because the provider uses the template generate endpoint (which only supports 'private', not 'internal'), and then immediately issues a PATCH to set 'internal' visibility without any retry/backoff when GitHub is not ready. Users need to add large write_delay_ms to get reliable applies, but is not feasible for this one issue.

Terraform Version

Terraform v1.9.5

  • provider registry.terraform.io/integrations/github v6.11.1 (and v6.11.0)

Reproducible on current releases.

Affected Resource(s)

  • github_repository (template create + visibility = "internal")

Terraform Configuration Files

resource "github_repository" "team_repos" {
  name        = "my-repo"
  template {
    owner      = "my-org"
    repository = "template-repo"
  }
  visibility     = "internal"
  auto_init      = true
  # additional fields as needed
}

Steps to Reproduce

  1. Create a template repo (must be "internal" or "private")
  2. Use github_repository resource with that template and visibility = "internal"
  3. terraform apply

Result:
Randomly (often), the operation fails with 422 error above if provider attempts to PATCH visibility too quickly after repo creation.

Debug Output

Terraform apply output:

Error: PATCH https://api.github.com/repos/my-org/my-repo: 422 Failed to update visibility. A previous repository operation is still in progress. []

This repeats unless write_delay_ms is set to large values (2-10 seconds or more).

The provider code path is resourceGithubRepositoryCreate() followed by resourceGithubRepositoryUpdate() which issues the PATCH for visibility = "internal" with no retry.

Proposed Fix:
- In resourceGithubRepositoryUpdate(), add retry/backoff for PATCH /repos/:org/:repo when 422 'previous repository operation' is returned for visibility changes after template creation.
- See also PR #3123 (fixed template create, but not the PATCH retry).

Panic Output

N/A

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    Type: Bug
    Status: Triage
    on Mar 24, 2026
  2. github-actions commented on Mar 24, 2026

    @github-actions

    👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

  3. gwendal-lecren commented on Jun 22, 2026

    @gwendal-lecren

    Ran into the same issue today with v6.12.0.

  4. kbraithwaite commented on Jul 22, 2026

    @kbraithwaite

    Afternoon! We are also running into this issue on version 6.12.1.
    For now we have added 422 to the list of retryable_errors in the provider config, which should help mitigate this issue 🙏🏽

  5. deiga commented on Jul 22, 2026

    @deiga
    Collaborator

    Thanks! This should be resolved in 6.14.0

  6. self-assigned this
    on Jul 22, 2026
  7. added this to the v6.14.0 milestone on Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Status: TriageType: Bugr/repository

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions