Skip to content

github_repository_ruleset: required_reviewers reviewer.id fails with 'cannot unmarshal string into int64' #3340

@dpwspoon-hi

Description

@dpwspoon-hi

Description

When using github_repository_ruleset with the pull_request.required_reviewers block, the resource creation POST to the GitHub API succeeds, but the provider fails to deserialize the response because reviewer.id is returned as a JSON string by the API while the Go struct expects int64.

Error

sdk-v2/provider2.go:572: sdk.helper_schema: json: cannot unmarshal string into Go struct field RepositoryRuleset.rules.required_reviewers.reviewer.id of type int64

Terraform / Provider Version

  • terraform-provider-github: v6.6.0 (also reproduced via Pulumi bridged provider @pulumi/github 6.12.1 which bundles terraform-provider-github v6.11.1)

Resource Configuration (minimal reproduction)

resource "github_repository_ruleset" "example" {
  name        = "reviewer-requirements"
  repository  = "my-repo"
  target      = "branch"
  enforcement = "active"

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

  rules {
    pull_request {
      required_approving_review_count = 0

      required_reviewers {
        file_patterns     = ["src/migrations/**"]
        minimum_approvals = 1

        reviewer {
          id   = data.github_team.my_team.id
          type = "Team"
        }
      }
    }
  }
}

data "github_team" "my_team" {
  slug = "my-team"
}

What Happens

  1. The provider successfully POSTs to POST /repos/{owner}/{repo}/rulesets — the ruleset is created in GitHub.
  2. The GitHub API returns a JSON response where reviewer.id is a string (e.g., "12345678").
  3. The Go provider attempts to unmarshal this into a struct field typed as int64.
  4. Deserialization fails with the error above.
  5. Because the provider can't parse the response, the resource is not recorded in state — but it does exist in GitHub. This creates an orphaned resource on every retry.

Expected Behavior

The provider should handle the reviewer.id field being returned as a string by the GitHub API and coerce it to int64 (e.g., via json.Number or a custom unmarshaler), since the API consistently returns numeric IDs as JSON strings in this response.

Additional Context

  • The required_reviewers feature is noted as beta in the provider SDK.
  • The bypass_actors[].actor_id field handles the same string-from-API pattern correctly — it's only required_reviewers[].reviewer.id that fails.
  • The orphaned-resource behavior (ruleset created in GitHub but not in state) makes this particularly disruptive, as subsequent applies fail with "Name must be unique" until the orphan is manually deleted via the API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions