Skip to content

[BUG]: Ruleset bypass_actors drift on every plan when the token cannot administer the ruleset #3687

Open

Description

@rriski

Expected Behavior

When the GitHub API response for a ruleset omits bypass_actors, Read keeps the bypass_actors value already in state. A plan with no configuration change shows no diff.

Actual Behavior

GitHub omits bypass_actors from GET /repos/{owner}/{repo}/rulesets/{id} when the caller cannot administer the ruleset. An admin caller gets "bypass_actors": [] when the list is empty, so a missing key and an empty list mean different things.

The provider treats both the same. flattenBypassActors returns []any{} for a nil slice, and Read writes it to state unconditionally:

Every plan run with such a token therefore proposes adding the configured bypass actors again:

  # github_repository_ruleset.default_branch will be updated in-place
  ~ resource "github_repository_ruleset" "default_branch" {
      + bypass_actors {
          + actor_type  = "OrganizationAdmin"
          + bypass_mode = "pull_request"
        }
        # ...
    }

Our setup is a common one: the plan job runs with a read-only GitHub App installation token (no Administration write), and only the apply job holds an admin-capable token. The plan never converges.

go-github's RepositoryRuleset.BypassActors decodes a missing key as nil and [] as an empty slice, so Read can tell the two cases apart without an extra request.

Terraform Version

OpenTofu v1.13.1, provider integrations/github v6.13.0 (latest release). The code linked above is from main at 20f916cb.

GitHub Installation Type

  • GitHub.com (Free, Pro, or Team)

Affected Resource(s)

  • github_repository_ruleset
  • github_organization_ruleset (same Read pattern)

Terraform Configuration Files

resource "github_repository_ruleset" "default_branch" {
  name        = "main"
  repository  = "example"
  target      = "branch"
  enforcement = "active"

  conditions {
    ref_name {
      include = ["~DEFAULT_BRANCH"]
      exclude = []
    }
  }

  bypass_actors {
    actor_type  = "OrganizationAdmin"
    bypass_mode = "pull_request"
  }

  rules {
    deletion         = true
    non_fast_forward = true
  }
}

Steps to Reproduce

  1. Apply the configuration above with a token that has admin rights on the repository.
  2. Run plan with a token that can read the repository but cannot administer it, for example a GitHub App installation token without the Administration write permission.
  3. The plan proposes + bypass_actors { ... }. Applying with the admin token and planning again with the read-only token shows the same diff.

The API difference is visible with gh api repos/<owner>/<repo>/rulesets/<id> --jq 'has("bypass_actors")': false for a non-admin caller, true for an admin caller, including when the list is empty.

Code of Conduct

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

Activity

  1. github-actions commented on Oct 19, 2026

    @github-actions

    👋 Hi, and thank you for opening this issue!

    This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can.

    You can help us prioritize by adding details, reproduction steps, or a 👍 to issues that matter to you, and by joining the discussion on open issues and PRs.


    🤖 This is an automated message.

  2. deiga commented on Oct 20, 2026

    @deiga
    Collaborator

    @rriski This is not a bug, this is how Terraform is supposed to work.

    I fully understand that using Read-only would be lovely, but that is up to the GitHub API team to introduce.

    We can't start breaking the Terraform contract just to work around a deficit in the GitHub API

  3. added
    Type: Bug
    Status: Triage
    on Oct 23, 2026
  4. robert-crandall commented on Nov 25, 2026

    @robert-crandall
    Contributor

    Linking #3688 from @rriski here for reference. We closed it as part of our temporary move to an issue-first model (see CONTRIBUTING.md), and want to keep the context and implementation approach handy when we pick this issue up.

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

    Status: TriageType: Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions