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/v2@v2.38.2/helper/customdiff/compose.go:52 +0xd9
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(...)
github.com/hashicorp/terraform-plugin-sdk/v2@v2.38.2/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
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_environment resource without a reviewers block 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]any
The 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.
Expected Behavior
Upgrading from
terraform-provider-githubv6.11.x to v6.12.x should work seamlessly for existinggithub_repository_environmentresources, including those that have noreviewersblock configured.Actual Behavior
terraform plancrashes with a nil pointer dereference panic in the newCustomizeDifffunction when processing existinggithub_repository_environmentresources that have no reviewers:Terraform Version
GitHub Installation Type
Affected Resource(s)
github_repository_environmentTerraform Configuration Files
Any
github_repository_environmentresource without areviewersblock that was created under v6.11.x triggers the panic when upgrading to v6.12.x.Steps to Reproduce
github_repository_environmentresource without areviewersblock using provider v6.11.xterraform planPlanResourceChangeDebug Output
Root cause analysis:
The
CustomizeDifffunction introduced in v6.12.0 (PR #3162) does not handle the case wherereviewersis empty or contains a nil element after state migration.In
resource_github_repository_environment.goline 133:The
StateUpgrader(SchemaVersion 0→1) only addsrepository_id— it does not transform thereviewersattribute. When the SDK coerces the old state into the new schema (wherereviewerschanged fromMaxItems: 6toMaxItems: 1), it can produce a list like[nil], which theCustomizeDiffdoesn't guard against.Note that
expandReviewersin the same file does have a proper nil check (if m != nil), butCustomizeDifflacks it.Suggested fix — add a nil guard before the type assertion:
This issue was filed with AI assistance (analysis and writeup). The bug, stack trace, and root cause were verified by a human engineer.