gitlab_project_protected_environment segfaults with dynamic deploy_access_levels in v16.4.0
The provider crashes when using a dynamic deploy_access_levels
with a condition in the for_each
in gitlab_project_protected_environment
:
❯ terraform plan
╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ValidateResourceConfig call. The plugin logs may contain more details.
╵
Stack trace from the terraform-provider-gitlab_v16.4.0 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x30 pc=0x102e47f3c]
goroutine 83 [running]:
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListValue.ToTerraformValue({{0x0, 0x0, 0x0}, {0x0, 0x0}, 0x0}, {0x103628f78, 0x1400059d0e0})
github.com/hashicorp/terraform-plugin-framework@v1.4.0/types/basetypes/list_value.go:208 +0x5c
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListValue.ElementsAs({{0x0, 0x0, 0x0}, {0x0, 0x0}, 0x0}, {0x103628f78, 0x1400059d0e0}, {0x103433920, 0x140005ae3d8}, ...)
github.com/hashicorp/terraform-plugin-framework@v1.4.0/types/basetypes/list_value.go:181 +0x60
gitlab.com/gitlab-org/terraform-provider-gitlab/internal/provider.(*gitlabProjectProtectedEnvironmentResource).ValidateConfig(0x103628f78?, {0x103628f78, 0x1400059d0e0}, {{{{0x10362dc30, 0x1400059d3e0}, {0x10349ff60, 0x1400059d200}}, {0x10362f740, 0x14000798050}}}, 0x140005ae360)
gitlab.com/gitlab-org/terraform-provider-gitlab/internal/provider/resource_gitlab_project_protected_environment.go:230 +0x1ec
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ValidateResourceConfig(0x140000f0f20, {0x103628f78, 0x1400059d0e0}, 0x14000788090, 0x140005515a0)
github.com/hashicorp/terraform-plugin-framework@v1.4.0/internal/fwserver/server_validateresourceconfig.go:93 +0x35c
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ValidateResourceConfig(0x140000f0f20, {0x103628f78?, 0x1400059cfc0?}, 0x140005ae228)
github.com/hashicorp/terraform-plugin-framework@v1.4.0/internal/proto6server/server_validateresourceconfig.go:47 +0x398
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ValidateResourceConfig(0x103628fb0?, {0x103628f78?, 0x1400059ccc0?}, 0x140005ae228)
github.com/hashicorp/terraform-plugin-mux@v0.12.0/tf6muxserver/mux_server_ValidateResourceConfig.go:36 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ValidateResourceConfig(0x1400025f5e0, {0x103628f78?, 0x1400059c180?}, 0x1400063a480)
github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/tf6server/server.go:727 +0x240
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ValidateResourceConfig_Handler({0x1035d7c80?, 0x1400025f5e0}, {0x103628f78, 0x1400059c180}, 0x14000624000, 0x0)
github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:359 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x140002521e0, {0x10362e5b8, 0x14000502b60}, 0x140002a2000, 0x14000413a10, 0x103c55268, 0x0)
google.golang.org/grpc@v1.57.0/server.go:1360 +0xc04
google.golang.org/grpc.(*Server).handleStream(0x140002521e0, {0x10362e5b8, 0x14000502b60}, 0x140002a2000, 0x0)
google.golang.org/grpc@v1.57.0/server.go:1737 +0x7c4
google.golang.org/grpc.(*Server).serveStreams.func1.1()
google.golang.org/grpc@v1.57.0/server.go:982 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 15
google.golang.org/grpc@v1.57.0/server.go:980 +0x154
Error: The terraform-provider-gitlab_v16.4.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.
It can be reproduced with this example:
terraform {
required_version = ">= 1.5"
required_providers {
gitlab = {
source = "gitlabhq/gitlab"
version = "16.4.0"
}
}
}
locals {
project_id = 38067424
environments = {
foo = {
access_level = "maintainer"
}
}
}
provider "gitlab" {}
resource "gitlab_project_protected_environment" "environment" {
for_each = local.environments
project = local.project_id
environment = each.key
dynamic "deploy_access_levels" {
# for_each = [each.value.access_level]
for_each = each.value.access_level != null ? [each.value.access_level] : []
content {
access_level = deploy_access_levels.value
}
}
}
It works properly when using for_each = [each.value.access_level]
instead, with no condition.
Likely related to !1679 (merged).
There was no segfault with v16.3.0.