[BUG]: Runtime panic in terraform-provider-github_v6.0.0 during github_repository_deployment_branch_policy resource creation
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/[email protected]/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/[email protected]/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/[email protected]/helper/schema/grpc_provider.go:1074 +0xd5c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000269680, {0x103f160?, 0xc0007c92f0?}, 0xc000660770)
github.com/hashicorp/[email protected]/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/[email protected]/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/[email protected]/server.go:1372 +0xdd1
google.golang.org/grpc.(*Server).handleStream(0xc00025e1e0, {0x10439b8, 0xc0003a9380}, 0xc000906240)
google.golang.org/[email protected]/server.go:1783 +0xfb8
google.golang.org/grpc.(*Server).serveStreams.func2.1()
google.golang.org/[email protected]/server.go:1016 +0x59
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 9
google.golang.org/[email protected]/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
- [X] I agree to follow this project's Code of Conduct
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/[email protected]/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/[email protected]/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/[email protected]/helper/schema/grpc_provider.go:667 +0x3e4
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x14000233680, {0x104faa3f0?, 0x14000ae28d0?}, 0x1400070e5a0)
github.com/hashicorp/[email protected]/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/[email protected]/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/[email protected]/server.go:1385 +0xb40
google.golang.org/grpc.(*Server).handleStream(0x140001a1000, {0x104faec38, 0x1400039b520}, 0x140004d8120)
google.golang.org/[email protected]/server.go:1796 +0xc00
google.golang.org/grpc.(*Server).serveStreams.func2.1()
google.golang.org/[email protected]/server.go:1029 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 9
google.golang.org/[email protected]/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.
Facing this with version terraform-provider-github_v5.42.0
Steps to Reproduce:
- Create Github Repository via Terraform(with and environment
foo) - Create Deployment Policy via UI/API.
- Create/Modify the branch policies on the same environment via Terraform.
resource "github_repository_environment" "env_foo" {
count = var.create_env_foo? 1 : 0
environment = "env-foo"
repository = github_repository.this.name
reviewers {
teams = [for team in data.github_team.approving_teams : team.id]
}
deployment_branch_policy {
protected_branches = false
custom_branch_policies = true
}
}
resource "github_repository_deployment_branch_policy" "foo_env_policy" {
count = var.create_env_foo ? 1 : 0
depends_on = [github_repository_environment.env_foo]
repository = github_repository.this.name
environment_name = github_repository_environment.env_foo[0].environment
name = "main"
}
Stack Trace
2024-08-14T09:28:23.1480772Z The plugin encountered an error, and failed to respond to the
2024-08-14T09:28:23.1481835Z plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain
2024-08-14T09:28:23.1482777Z more details.
2024-08-14T09:28:23.4009497Z
2024-08-14T09:28:23.4010964Z Stack trace from the terraform-provider-github_v5.42.0 plugin:
2024-08-14T09:28:23.4012047Z
2024-08-14T09:28:23.4012793Z panic: runtime error: invalid memory address or nil pointer dereference
2024-08-14T09:28:23.4014590Z [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x100e21d]
2024-08-14T09:28:23.4015652Z
2024-08-14T09:28:23.4016086Z goroutine 48 [running]:
2024-08-14T09:28:23.4018585Z github.com/integrations/terraform-provider-github/v5/github.resourceGithubRepositoryDeploymentBranchPolicyCreate(0xc0007c9500, {0x10c4100?, 0xc0002a5240})
2024-08-14T09:28:23.4022173Z github.com/integrations/terraform-provider-github/v5/github/resource_github_repository_deployment_branch_policy.go:88 +0x2fd
2024-08-14T09:28:23.4025588Z github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc0007a46e0, 0xc000804780, 0xc0005d55a0, {0x10c4100, 0xc0002a5240})
2024-08-14T09:28:23.4028535Z github.com/hashicorp/[email protected]/helper/schema/resource.go:320 +0x637
2024-08-14T09:28:23.4031386Z github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc0001a1980, 0xc0005cb8e8, 0x136789d?, 0xf?)
2024-08-14T09:28:23.4034106Z github.com/hashicorp/[email protected]/helper/schema/provider.go:294 +0x6a
2024-08-14T09:28:23.4037958Z github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000107a80, {0xc0007c9030?, 0x4c3b06?}, 0xc0007c9030)
2024-08-14T09:28:23.4041133Z github.com/hashicorp/[email protected]/internal/helper/plugin/grpc_provider.go:895 +0x7c5
2024-08-14T09:28:23.4044779Z github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1309dc0?, 0xc000107a80}, {0x17246d0, 0xc0007a1320}, 0xc0007c8fc0, 0x0)
2024-08-14T09:28:23.4048105Z github.com/hashicorp/[email protected]/internal/tfplugin5/tfplugin5.pb.go:3305 +0x169
2024-08-14T09:28:23.4050933Z google.golang.org/grpc.(*Server).processUnaryRPC(0xc00028c000, {0x1729e10, 0xc0007fc340}, 0xc000806b40, 0xc00026c390, 0x2041d60, 0x0)
2024-08-14T09:28:23.4053189Z google.golang.org/[email protected]/server.go:1335 +0xde7
2024-08-14T09:28:23.4055171Z google.golang.org/grpc.(*Server).handleStream(0xc00028c000, {0x1729e10, 0xc0007fc340}, 0xc000806b40, 0x0)
2024-08-14T09:28:23.4057526Z google.golang.org/[email protected]/server.go:1712 +0x9e7
2024-08-14T09:28:23.4058976Z google.golang.org/grpc.(*Server).serveStreams.func1.1()
2024-08-14T09:28:23.4060417Z google.golang.org/[email protected]/server.go:947 +0xbb
2024-08-14T09:28:23.4062105Z created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 25
2024-08-14T09:28:23.4063864Z google.golang.org/[email protected]/server.go:958 +0x145
2024-08-14T09:28:23.4064739Z
2024-08-14T09:28:23.4065490Z Error: The terraform-provider-github_v5.42.0 plugin crashed!
2024-08-14T09:28:23.4066497Z
2024-08-14T09:28:23.4067516Z This is always indicative of a bug within the plugin. It would be immensely
2024-08-14T09:28:23.4069622Z helpful if you could report the crash with the plugin's maintainers so that it
2024-08-14T09:28:23.4071431Z can be fixed. The output above should help diagnose the issue.
Also a problem with version 6.3.0.
Terraform Configuration Files
terraform {
required_providers {
github = {
source = "integrations/github"
version = "6.3.0"
}
}
}
resource "github_repository_environment" "foo" {
environment = "foo"
repository = github_repository.foo.name
deployment_branch_policy {
custom_branch_policies = true
protected_branches = false
}
}
resource "github_repository_deployment_branch_policy" "foo" {
name = "main"
repository = github_repository.foo.name
environment_name = github_repository_environment.foo.environment
}
Output
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
Stack trace from the terraform-provider-github_v6.3.0 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc8a51d]
goroutine 762 [running]:
github.com/integrations/terraform-provider-github/v6/github.resourceGithubRepositoryDeploymentBranchPolicyCreate(0xc00018d000, {0xd23ba0, 0xc0007170c0})
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(0x1062030?, {0x1062030?, 0xc00084ab40?}, 0xd?, {0xd23ba0?, 0xc0007170c0?})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:794 +0x15f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0003a5dc0, {0x1062030, 0xc00084ab40}, 0xc00040a410, 0xc00018cd80, {0xd23ba0, 0xc0007170c0})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:937 +0xa89
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0003725e8, {0x1062030?, 0xc00084aa80?}, 0xc0000a07d0)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1153 +0xd5c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc00026f680, {0x1062030?, 0xc00084a2a0?}, 0xc00020ca10)
github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xec8a80, 0xc00026f680}, {0x1062030, 0xc00084a2a0}, 0xc000555f00, 0x0)
github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000189000, {0x1062030, 0xc00084a210}, {0x1066930, 0xc000236180}, 0xc000848900, 0xc0004764b0, 0x16ec538, 0x0)
google.golang.org/[email protected]/server.go:1369 +0xdf8
google.golang.org/grpc.(*Server).handleStream(0xc000189000, {0x1066930, 0xc000236180}, 0xc000848900)
google.golang.org/[email protected]/server.go:1780 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
google.golang.org/[email protected]/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 27
google.golang.org/[email protected]/server.go:1030 +0x125
Error: The terraform-provider-github_v6.3.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.
We are having the same issue with the deployment branch policy. Is there a work around or a fix that is being worked on??
The issue in our case was the branch that we were adding to the environment already existed there and the provider did not seem to handle the api response properly in this case. We manually deleted the duplicates from github UI and then the apply succeeded.
👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!