Skip to content

[BUG]: v6.12.0 panic: nil pointer dereference in updateUserCollaboratorsAndInvites when AddCollaborator returns 204 No Content for org members #3370

Closed

Description

@mauro-boffito

Expected Behavior

github_repository_collaborators should successfully create or update the resource when one of the desired users is an organization member who is not yet a direct collaborator. GitHub's REST API returns 204 No Content in that case (the user is promoted to direct collaborator immediately with no invitation required). The provider is expected to record the user and continue.

Actual Behavior

The provider crashes with a nil pointer dereference (SIGSEGV). client.Repositories.AddCollaborator returns a nil invitation object on the 204 path, but the code at github/resource_github_repository_collaborators.go:694 unconditionally dereferences inv.ID:

inv, _, err := client.Repositories.AddCollaborator(ctx, owner, repoName, inUser.login, &github.RepositoryAddCollaboratorOptions{Permission: inUser.permission})
if err != nil {
    return nil, err
}
inUser.invitationID = inv.ID                     // <- panic here when inv == nil
ghInvites = append(ghInvites, inUser)

Reference to the PUT collaborators endpoint documentation (204 response for existing-access org members):
https://docs.github.com/rest/collaborators/collaborators#add-a-repository-collaborator

Likely regression source: #3233 (feat: Refactor repository collaborators, shipped in v6.12.0).

Terraform Version

Terraform v1.9.x
on darwin_arm64
+ provider registry.terraform.io/integrations/github v6.12.0

(Also reproduced on linux_amd64 in CI.)

Affected Resource(s)

  • github_repository_collaborators

Terraform Configuration Files

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "6.12.0"
    }
  }
}

provider "github" {
  owner = "my-org"
}

# The user below must be a member of "my-org" and NOT yet a direct
# collaborator on the target repository. GitHub will return 204 No Content
# from PUT /repos/{owner}/{repo}/collaborators/{username}, triggering the
# panic inside the provider.
resource "github_repository_collaborators" "main" {
  repository = "some-repo"

  user {
    username   = "an-org-member"
    permission = "admin"
  }
}

Steps to Reproduce

  1. In your org, pick a user who is an org member but not a direct collaborator on some-repo.
  2. Apply the configuration above against v6.12.0.
  3. The provider panics during the Create call.

Reproduces 100% of the time under these conditions.

Debug Output

Relevant provider log lines right before the crash (redacted):


github_repository_collaborators.main["some-repo"]: Creating...
[INFO]  Inviting user an-org-member to repo some-repo with permission admin.

Panic Output

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xde9469]

goroutine 77 [running]:
github.com/integrations/terraform-provider-github/v6/github.updateUserCollaboratorsAndInvites(...)
	github.com/integrations/terraform-provider-github/v6/github/resource_github_repository_collaborators.go:694 +0xe09
github.com/integrations/terraform-provider-github/v6/github.resourceGithubRepositoryCollaboratorsCreate(...)
	github.com/integrations/terraform-provider-github/v6/github/resource_github_repository_collaborators.go:199 +0x3f1
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(...)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:849 +0x119
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(...)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:980 +0xafd
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(...)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1499 +0x10c9
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(...)
	github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:944 +0x3b9
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler(...)
	github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:789 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(...)
	google.golang.org/[email protected]/server.go:1431 +0xfdc
google.golang.org/grpc.(*Server).handleStream(...)
	google.golang.org/[email protected]/server.go:1842 +0xb88
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/[email protected]/server.go:1061 +0x7f
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 24
	google.golang.org/[email protected]/server.go:1072 +0x11d

Error: The terraform-provider-github_v6.12.0 plugin crashed!

Code of Conduct

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

Activity

  1. added
    Type: Bug
    Status: Triage
    on Apr 24, 2026
  2. github-actions commented on Apr 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. removed
    Status: Triage
    on Apr 25, 2026
  4. added theissue type on Apr 25, 2026
  5. added
    vNextPatch
    on Apr 25, 2026
  6. added this to the v6.12.1 milestone on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugvNextPatch

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions