Skip to content

[BUG]: #2700

@nbarber-macu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is being looked at and prioritizedType: BugSomething isn't working as documented

    Type

    No type

    Projects

    Status

    🆕 Triage

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions