Skip to content

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

Closed

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/[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

  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.

Activity

  1. github-actions commented on May 28, 2026

    @github-actions

    👋 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! 🚀

  2. deiga commented on May 28, 2026

    @deiga
    Collaborator

    Sorry that you are bumping into this! Could you add the DEBUG level plan output as well?

  3. mwielgosz-esky commented on Jun 1, 2026

    @mwielgosz-esky
    Author

    @deiga Here's the TF_LOG=DEBUG plan output as requested:

    Environment:

    • Terraform v1.15.4
    • terraform-provider-github v6.12.1
    • OS: Linux (amd64)

    The panic triggers during PlanResourceChange for github_repository_environment resources that have environments without reviewers in state (created on v6.11.x, then provider upgraded to v6.12.1).

    Relevant DEBUG excerpt (sanitized timestamps):

    WARN  Provider "registry.terraform.io/integrations/github" produced an invalid plan for
      module.example.github_repository_environment.github_repository_environment["production"],
      but we are tolerating it because it is using the legacy plugin SDK.
        The following problems may be the cause of any confusing errors from downstream operations:
          - .wait_timer: planned value cty.NumberIntVal(0) for a non-computed attribute
          - .reviewers[0].teams: planned value cty.NullVal(cty.Set(cty.Number)) does not match config value cty.SetValEmpty(cty.Number)
    
    ERROR provider.terraform-provider-github_v6.12.1: panic: interface conversion: interface {} is nil, not map[string]interface {}
    ERROR provider.terraform-provider-github_v6.12.1
    ERROR provider.terraform-provider-github_v6.12.1: goroutine 287 [running]:
    ERROR provider.terraform-provider-github_v6.12.1: github.com/integrations/terraform-provider-github/v6/github.resourceGithubRepositoryEnvironmentDiff({0x1260dc8?, 0x1f2255007170?}, 0x1f2255483a40?, {0xf42c40?, 0x1f2254e3e540?})
    ERROR provider.terraform-provider-github_v6.12.1: 	github.com/integrations/terraform-provider-github/v6/github/resource_github_repository_environment.go:133 +0x1c5
    ERROR provider.terraform-provider-github_v6.12.1: github.com/integrations/terraform-provider-github/v6/github.resourceGithubRepositoryEnvironment.All.func3({0x1260dc8, 0x1f2255007170}, 0x1f2255483a40, {0xf42c40, 0x1f2254e3e540})
    ERROR provider.terraform-provider-github_v6.12.1: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/customdiff/compose.go:52 +0xd9
    ERROR provider.terraform-provider-github_v6.12.1: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMapWithIdentity.Diff(...)
    ERROR provider.terraform-provider-github_v6.12.1: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:756 +0x4f4
    ERROR provider.terraform-provider-github_v6.12.1: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff(...)
    ERROR provider.terraform-provider-github_v6.12.1: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1034 +0x12f
    ERROR provider.terraform-provider-github_v6.12.1: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(...)
    ERROR provider.terraform-provider-github_v6.12.1: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1133 +0xeff
    ERROR provider.terraform-provider-github_v6.12.1: github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange(...)
    ERROR provider.terraform-provider-github_v6.12.1: 	github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:904 +0x3d9
    (... grpc server frames ...)
    
    ERROR provider: plugin process exited: plugin=.terraform/providers/registry.terraform.io/integrations/github/6.12.1/linux_amd64/terraform-provider-github_v6.12.1 id=47639 error="exit status 2"
    

    Key observations from the DEBUG output:

    1. 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 a reviewers block with nil inner maps for environments that never had reviewers configured.

    2. The panic at resource_github_repository_environment.go:133 confirms the nil interface assertion — the CustomizeDiff function tries to access reviewers[0] as map[string]interface{} but gets nil instead.

    3. The crash kills the provider process, cascading Plugin did not respond errors to all other github_repository_environment resources in the same plan.

    Reproduction recipe:

    1. Create a github_repository_environment without a reviewers block using provider ≤ v6.11.x
    2. Upgrade provider to v6.12.0 or v6.12.1
    3. Run terraform plan — the state schema upgrade injects a nil reviewers entry, and CustomizeDiff panics
  4. added
    Type: Bug
    on Jun 3, 2026
  5. added theissue type on Jun 3, 2026
  6. added this to the v6.13.0 milestone on Jun 3, 2026
  7. self-assigned this
    on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type: Bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions