integrations / integrations/terraform-provider-github

[BUG]: github_repository_environment fails to refresh when an Enterprise Team is a required reviewer (reviewer.Type "BusinessTeam")

Open
#3,632 2 comments 0 reactions 0 assignees View on GitHub
Status: Needs info Status: Triage Type: Bug
Dominant language
Go
Stars
1.2k
Forks
1k
Avg merge
1d 14h
Merged PRs (30d)
8

Description

### Expected Behavior

Reading/refreshing a `github_repository_environment` whose required reviewers include a GitHub **Enterprise Team** should succeed — either representing that reviewer in state, or ignoring it gracefully.

### Actual Behavior

Any `plan`/`apply` that refreshes the resource fails:

```
Error: reviewer.Type is *string, not a string of 'User' or 'Team', unable to unmarshal

with github_repository_environment.notify_gate[""],
on main.repos.tf line 232, in resource "github_repository_environment" "notify_gate":
232: resource "github_repository_environment" "notify_gate" {
```

Because Terraform refreshes the whole state, **a single environment with an Enterprise Team reviewer blocks every `plan`/`apply` in the workspace**, including for completely unrelated resources. The resource becomes unmanageable until the Enterprise Team reviewer is removed out-of-band via the REST API or UI.

### Terraform Version

```
Terraform v1.15.8
on windows_amd64
+ provider registry.terraform.io/integrations/github v6.13.0
```

### GitHub Installation Type

- [ ] GitHub.com (Free, Pro, or Team)
- [ ] GitHub Enterprise Server (on-premises)
- [ ] GitHub Enterprise Cloud with Personal Accounts (github.com)
- [x] GitHub Enterprise Cloud with Managed Users/EMU (github.com)
- [ ] GitHub Enterprise Cloud with Data Residency (*.ghe.com)
- [ ] I don't know

### Affected Resource(s)

- `github_repository_environment` (read/refresh path)
- Likely anything else decoding required reviewers from the environments API (e.g. the corresponding data source)

### Terraform Configuration Files

```hcl
resource "github_repository_environment" "notify_gate" {
for_each = var.repositories
environment = "notify-gate"
repository = github_repository.iac[each.key].name

reviewers {
users = [2363016, 1317356] # two named users
}
}

The Enterprise Team reviewer is **not** declared in Terraform — it was added out-of-band, which is enough to break refresh permanently. There is also no way to express an Enterprise Team in the `reviewers` block (`users`/`teams` only), so it cannot be adopted into config as a workaround.
```

### Steps to Reproduce

1. On GitHub Enterprise Cloud with data residency + Enterprise Managed Users, create an environment with required reviewers via Terraform (users and/or org teams).
2. Add an **Enterprise Team** as an additional required reviewer via the UI or `PUT /repos/{owner}/{repo}/environments/{environment_name}`.
3. Run `terraform plan` → the error above. It persists until the Enterprise Team reviewer is removed.

### Debug Output

`GET /repos/{owner}/{repo}/environments/{environment_name}` returns a reviewer whose top-level `type` is `BusinessTeam`, with a nested reviewer object of `type: "enterprise"`:

```json
{
"type": "BusinessTeam",
"reviewer": {
"name": "",
"id": 2418211,
"slug": "ent:",
"privacy": "closed",
"type": "enterprise",
"enterprise_id": 23181,
"permission": "pull",
"parent": null
}
}
```

For contrast, a normal user reviewer in the same response is `"type": "User"`.

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start with the github_repository_environment read/refresh path and the environments API response from GET /repos/{owner}/{repo}/environments/{environment_name}. Trace how required reviewers with type "BusinessTeam" are decoded, including the possible corresponding data source. Done means terraform plan/apply refreshes successfully when an Enterprise Team reviewer is present, either by preserving it in state or ignoring it safely.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, go, terraform
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.