Repository navigation
Description
Expected Behavior
Upgrading from terraform-provider-github v6.11.x to v6.12.x should work seamlessly for existing github_repository_environment resources, including those that have no reviewers block configured.
Actual Behavior
terraform plan crashes with a nil pointer dereference panic in the new CustomizeDiff function when processing existing github_repository_environment resources that have no reviewers:
Stack trace from the terraform-provider-github_v6.12.1 plugin:
panic: interface conversion: interface {} is nil, not map[string]interface {}
goroutine 203 [running]:
github.com/integrations/terraform-provider-github/v6/github.resourceGithubRepositoryEnvironmentDiff({0x1260dc8?, 0x20d058af4c90?}, 0x20d058930820?, {0xf42c40?, 0x20d0587b6e80?})
github.com/integrations/terraform-provider-github/v6/github/resource_github_repository_environment.go:133 +0x1c5
github.com/integrations/terraform-provider-github/v6/github.resourceGithubRepositoryEnvironment.All.func3(...)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/customdiff/compose.go:52 +0xd9
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(...)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1133 +0xeff
Terraform Version
Terraform v1.15.4
on linux_amd64
+ provider registry.terraform.io/integrations/github v6.12.1
GitHub Installation Type
- GitHub Enterprise Cloud with Personal Accounts (github.com)
Affected Resource(s)
github_repository_environment
Terraform Configuration Files
resource "github_repository_environment" "example" {
repository = "my-repo"
environment = "staging"
# no reviewers block — this is the trigger
}Any github_repository_environment resource without a reviewers block that was created under v6.11.x triggers the panic when upgrading to v6.12.x.
Steps to Reproduce
- Create a
github_repository_environmentresource without areviewersblock using provider v6.11.x - Upgrade the provider to v6.12.0 or v6.12.1
- Run
terraform plan - The provider panics during
PlanResourceChange
Debug Output
Root cause analysis:
The CustomizeDiff function introduced in v6.12.0 (PR #3162) does not handle the case where reviewers is empty or contains a nil element after state migration.
In resource_github_repository_environment.go line 133:
o := v.([]any)[0] // returns nil when reviewers list has a nil element
o.(map[string]any)["teams"] // panics: nil is not map[string]anyThe StateUpgrader (SchemaVersion 0→1) only adds repository_id — it does not transform the reviewers attribute. When the SDK coerces the old state into the new schema (where reviewers changed from MaxItems: 6 to MaxItems: 1), it can produce a list like [nil], which the CustomizeDiff doesn't guard against.
Note that expandReviewers in the same file does have a proper nil check (if m != nil), but CustomizeDiff lacks it.
Suggested fix — add a nil guard before the type assertion:
if v != nil {
items := v.([]any)
if len(items) > 0 && items[0] != nil {
o := items[0].(map[string]any)
// ... rest of the logic
}
}This issue was filed with AI assistance (analysis and writeup). The bug, stack trace, and root cause were verified by a human engineer.
Activity
github-actions commentedon May 28, 2026
👋 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! 🚀deiga commentedon May 28, 2026
Sorry that you are bumping into this! Could you add the DEBUG level plan output as well?
mwielgosz-esky commentedon Jun 1, 2026
@deiga Here's the
TF_LOG=DEBUGplan output as requested:Environment:
The panic triggers during
PlanResourceChangeforgithub_repository_environmentresources that have environments without reviewers in state (created on v6.11.x, then provider upgraded to v6.12.1).Relevant DEBUG excerpt (sanitized timestamps):
Key observations from the DEBUG output:
The WARN before the panic shows the plan already detected inconsistency:
.reviewers[0].teams: planned value cty.NullVal(cty.Set(cty.Number)) does not match config value cty.SetValEmpty(cty.Number)— the state schema upgrade (v0→v1 from PR feat: Fixup repository environment logic #3162) introduces areviewersblock with nil inner maps for environments that never had reviewers configured.The panic at
resource_github_repository_environment.go:133confirms the nil interface assertion — theCustomizeDifffunction tries to accessreviewers[0]asmap[string]interface{}but getsnilinstead.The crash kills the provider process, cascading
Plugin did not responderrors to all othergithub_repository_environmentresources in the same plan.Reproduction recipe:
github_repository_environmentwithout areviewersblock using provider ≤ v6.11.xterraform plan— the state schema upgrade injects a nil reviewers entry, andCustomizeDiffpanics