integrations / terraform-provider-github

Terraform GitHub provider
https://www.terraform.io/docs/providers/github/
MIT License
879 stars 719 forks source link

[BUG]: Runtime panic in terraform-provider-github_v6.0.0 during github_repository_deployment_branch_policy resource creation #2178

Open imperius361 opened 5 months ago

imperius361 commented 5 months ago

Expected Behavior

The github_repository_deployment_branch_policy resource should be created without errors when applying the Terraform configuration.

Actual Behavior

When attempting to create a github_repository_deployment_branch_policy resource, the terraform-provider-github plugin v6.0.0 crashes with a runtime error indicating an invalid memory address or nil pointer dereference. This results in a failed Terraform apply operation.

Terraform Version

Terraform v1.4.5 on linux_amd64 + provider registry.terraform.io/integrations/github v6.0.0

Affected Resource(s)

github_repository_deployment_branch_policy

Terraform Configuration Files

resource "github_repository_environment" "dev" {
  repository = github_repository.repository.name
  environment = "dev"
  deployment_branch_policy {
    protected_branches = false
    custom_branch_policies = true
  }
}

resource "github_repository_deployment_branch_policy" "dev" {
  for_each = toset(["dev", "hotfix/*", "feature/*"])
  depends_on = [ github_repository_environment.dev ]
  repository = github_repository.repository.name
  environment_name = "dev"
  name = each.value
}

Steps to Reproduce

terraform apply with a configuration that includes a github_repository_deployment_branch_policy resource.

Debug Output

No response

Panic Output

Stack trace from the terraform-provider-github_v6.0.0 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc76ddd]

goroutine 118 [running]:
github.com/integrations/terraform-provider-github/v6/github.resourceGithubRepositoryDeploymentBranchPolicyCreate(0xc0005a2b80, {0xd0dfe0, 0xc000644900})
github.com/integrations/terraform-provider-github/v6/github/resource_github_repository_deployment_branch_policy.go:88 +0x2fd
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x103f160?, {0x103f160?, 0xc000463f50?}, 0xd?, {0xd0dfe0?, 0xc000644900?})
github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:766 +0x15f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0003b5340, {0x103f160, 0xc000463f50}, 0xc000666410, 0xc000739700, {0xd0dfe0, 0xc000644900})
github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:909 +0xa89
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000379e90, {0x103f160?, 0xc0007c9cb0?}, 0xc0007a3c20)
github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/grpc_provider.go:1074 +0xd5c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000269680, {0x103f160?, 0xc0007c92f0?}, 0xc000660770)
github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/tf5server/server.go:859 +0x56f
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xea58c0, 0xc000269680}, {0x103f160, 0xc0007c92f0}, 0xc0007d6100, 0x0)
github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:503 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00025e1e0, {0x103f160, 0xc0007c9230}, {0x10439b8, 0xc0003a9380}, 0xc000906240, 0xc000462ae0, 0x16b1498, 0x0)
google.golang.org/grpc@v1.60.0/server.go:1372 +0xdd1
google.golang.org/grpc.(*Server).handleStream(0xc00025e1e0, {0x10439b8, 0xc0003a9380}, 0xc000906240)
google.golang.org/grpc@v1.60.0/server.go:1783 +0xfb8
google.golang.org/grpc.(*Server).serveStreams.func2.1()
google.golang.org/grpc@v1.60.0/server.go:1016 +0x59
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 9
google.golang.org/grpc@v1.60.0/server.go:1027 +0x106

Error: The terraform-provider-github_v6.0.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Code of Conduct

elwood-djones commented 3 months ago

I get the exact same error for the resource github_repository_ruleset in version 6.2.1 The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x104bdd054]

goroutine 676 [running]:
github.com/integrations/terraform-provider-github/v6/github.resourceGithubRepositoryRulesetRead(0x1400041ed80, {0x104dc10c0?, 0x1400026ac00?})
    github.com/integrations/terraform-provider-github/v6/github/resource_github_repository_ruleset.go:480 +0x494
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x104faa3f0?, {0x104faa3f0?, 0x1400093a1b0?}, 0xd?, {0x104dc10c0?, 0x1400026ac00?})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:783 +0x130
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x140003f5260, {0x104faa3f0, 0x1400093a1b0}, 0x1400054f380, {0x104dc10c0, 0x1400026ac00})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:1089 +0x408
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x140003745d0, {0x104faa3f0?, 0x1400047f290?}, 0x14000791440)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/grpc_provider.go:667 +0x3e4
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x14000233680, {0x104faa3f0?, 0x14000ae28d0?}, 0x1400070e5a0)
    github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/tf5server/server.go:775 +0x3c8
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x104f644c0, 0x14000233680}, {0x104faa3f0, 0x14000ae28d0}, 0x14000895e00, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:482 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x140001a1000, {0x104faa3f0, 0x14000ae2810}, {0x104faec38, 0x1400039b520}, 0x140004d8120, 0x1400047e180, 0x10560cc08, 0x0)
    google.golang.org/grpc@v1.61.1/server.go:1385 +0xb40
google.golang.org/grpc.(*Server).handleStream(0x140001a1000, {0x104faec38, 0x1400039b520}, 0x140004d8120)
    google.golang.org/grpc@v1.61.1/server.go:1796 +0xc00
google.golang.org/grpc.(*Server).serveStreams.func2.1()
    google.golang.org/grpc@v1.61.1/server.go:1029 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 9
    google.golang.org/grpc@v1.61.1/server.go:1040 +0x13c

Error: The terraform-provider-github_v6.2.1 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.