mrparkers / terraform-provider-keycloak

Terraform provider for Keycloak
https://registry.terraform.io/providers/mrparkers/keycloak/latest/docs
MIT License
612 stars 300 forks source link

Provider crash on realm creation when security defneses is empty block #822

Open KLeventeAkos opened 1 year ago

KLeventeAkos commented 1 year ago

Catched a plugin panic in case of empty security_defenses{} block. Shouldn't be a problem since nobody in their right mind would use an empty block but its a bug none the less.

Terraform version 1.3.7 Provider version 4.2.0 example code:

resource "keycloak_realm" "this" {
  realm             = "panic"
  security_defenses {

  }
}

provider "keycloak" {
  client_id                = "admin-cli"
  username                 = "someuser"
  password                 = "somepw"
  url                      = "somehost"
  tls_insecure_skip_verify = false

}

error log:

keycloak_realm.this: Creating...
╷
│ Error: Plugin did not respond
│ 
│   with keycloak_realm.this,
│   on main.tf line 1, in resource "keycloak_realm" "this":
│    1: resource "keycloak_realm" "this" {
│ 
│ 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-keycloak_v4.2.0 plugin:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 41 [running]:
github.com/mrparkers/terraform-provider-keycloak/provider.getRealmFromData(0x0?)
        github.com/mrparkers/terraform-provider-keycloak/provider/resource_keycloak_realm.go:961 +0x37f4
github.com/mrparkers/terraform-provider-keycloak/provider.resourceKeycloakRealmCreate({0xe9bfe8, 0xc0007b0600}, 0x0?, {0xd3fc20?, 0xc00009b020?})
        github.com/mrparkers/terraform-provider-keycloak/provider/resource_keycloak_realm.go:1364 +0x6a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc000472540, {0xe9c020, 0xc00035ef00}, 0xd?, {0xd3fc20, 0xc00009b020})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:707 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000472540, {0xe9c020, 0xc00035ef00}, 0xc00012b930, 0xc000128c00, {0xd3fc20, 0xc00009b020})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:837 +0xa7a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000119608, {0xe9c020?, 0xc00035ede0?}, 0xc0000a4fa0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0003fc960, {0xe9c020?, 0xc00035e3f0?}, 0xc0000c60e0)
        github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/tf5server/server.go:818 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xd111a0?, 0xc0003fc960}, {0xe9c020, 0xc00035e3f0}, 0xc0000c6070, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000448000, {0xe9ec00, 0xc000502d00}, 0xc000444000, 0xc0004d8630, 0x1393480, 0x0)
        google.golang.org/grpc@v1.48.0/server.go:1295 +0xb0b
google.golang.org/grpc.(*Server).handleStream(0xc000448000, {0xe9ec00, 0xc000502d00}, 0xc000444000, 0x0)
        google.golang.org/grpc@v1.48.0/server.go:1636 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.48.0/server.go:932 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.48.0/server.go:930 +0x28a

Error: The terraform-provider-keycloak_v4.2.0 plugin crashed!