Skip to content

[BUG]: github_repository_environment CustomizeDiff panics on nil reviewers after upgrade from v6.11.x to v6.12.x #3455

@mwielgosz-esky

Description

@mwielgosz-esky

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

  • 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

  1. Create a github_repository_environment resource without a reviewers block using provider v6.11.x
  2. Upgrade the provider to v6.12.0 or v6.12.1
  3. Run terraform plan
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions