Skip to content

[BUG]: Multiple github_repository_collaborators blocks interefere with eachother after creation #3252

@spacez320

Description

@spacez320

Expected Behavior

When supplying multiple github_repository_collaborators blocks referencing the same repository, I would expect them to independently manage permissions against a repository on the first terraform apply. A follow-up terraform apply would then report "No changes".

Actual Behavior

Consider the following Terraform code:

resource "github_repository_collaborators" "collaborators_1" {
  repository = github_repository.repository.name

  user {
    permission = "triage"
    username   = "someone"
  }
}

resource "github_repository_collaborators" "collaborators_2" {
  repository = github_repository.repository.name

  user {
    permission = "pull"
    username   = "someone2"
  }
}

This does produce the following plan, and applies successfully.

Terraform will perform the following actions:

  # github_repository_collaborators.collaborators_1 will be created
  + resource "github_repository_collaborators" "collaborators_1" {
      + id             = (known after apply)
      + invitation_ids = (known after apply)
      + repository     = "something"

      + user {
          + permission = "triage"
          + username   = "someone"
        }
    }

  # github_repository_collaborators.collaborators_2 will be created
  + resource "github_repository_collaborators" "collaborators_2" {
      + id             = (known after apply)
      + invitation_ids = (known after apply)
      + repository     = "something"

      + user {
          + permission = "pull"
          + username   = "someone2"
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Immediate running another apply with no changes does this:

Terraform will perform the following actions:

  # github_repository_collaborators.collaborators_1 will be updated in-place
  ~ resource "github_repository_collaborators" "collaborators_1" {
        id             = "something"
      ~ invitation_ids = {} -> (known after apply)
        # (1 unchanged attribute hidden)

      - user {
          - permission = "pull" -> null
          - username   = "someone2" -> null
        }

        # (1 unchanged block hidden)
    }

  # github_repository_collaborators.collaborators_2 will be updated in-place
  ~ resource "github_repository_collaborators" "collaborators_2" {
        id             = "something
      ~ invitation_ids = {} -> (known after apply)
        # (1 unchanged attribute hidden)

      - user {
          - permission = "triage" -> null
          - username   = "someone" -> null
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

If you apply this, all users are removed from the repository. It's almost like the provider thinks each block is the same resource?

A work-around is to use a single github_repository_collaborators block for all user and team assignments, but judging from the documentation it doesn't seem like this is intentional.

Terraform Version

Terraform v1.13.3
on darwin_arm64

  • provider registry.terraform.io/hashicorp/aws v6.32.1
  • provider registry.terraform.io/integrations/github v6.11.1

Affected Resource(s)

  • github_repository_collaborators

Terraform Configuration Files

n/a

Steps to Reproduce

See actual outcome.

Debug Output

n/a

Panic Output

n/a

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions