Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interface {} is nil, not map[string]interface {} in SMTP configuration #535

Closed
DecentM opened this issue May 22, 2021 · 2 comments
Closed

Comments

@DecentM
Copy link

DecentM commented May 22, 2021

Thanks for making this plugin! It's my first time writing Terraform config, so I can accept that this could be something I overlooked. The error output says that this is definitely an issue with the plugin, so I thought I'd report it.

The issue occurs during terraform apply. terraform plan succeeds in generating the execution plan.

Error message (click to expand):
Stack trace from the terraform-provider-keycloak_v3.0.1.exe plugin:

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

goroutine 59 [running]:
github.com/mrparkers/terraform-provider-keycloak/provider.getRealmFromData(0xc000042c00, 0x0, 0x1ba5180, 0xc0005d9890)
        github.com/mrparkers/terraform-provider-keycloak/provider/resource_keycloak_realm.go:647 +0x46a7
github.com/mrparkers/terraform-provider-keycloak/provider.resourceKeycloakRealmUpdate(0xc000042c00, 0x1cf7300, 0xc00024a120, 0x0, 
0xffffffffffffffff)
        github.com/mrparkers/terraform-provider-keycloak/provider/resource_keycloak_realm.go:1225 +0x4b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc000785130, 0x1ea3fe0, 0xc0001c2140, 0xc000042c00, 0x1cf7300, 0xc00024a120, 0x0, 0x0, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.0.2-0.20200817173939-b72757e734f6/helper/schema/resource.go:293 +0x95     
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000785130, 0x1ea3fe0, 0xc0001c2140, 0xc00025a4d0, 
0xc0007d20a0, 0x1cf7300, 0xc00024a120, 0x0, 0x0, 0x0, ...)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.0.2-0.20200817173939-b72757e734f6/helper/schema/resource.go:395 +0x39e    
github.com/hashicorp/terraform-plugin-sdk/v2/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000004100, 0x1ea3fe0, 0xc0001c2140, 0xc00025a0e0, 0xc000004100, 0xc000004110, 0x1d4fdb0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.0.2-0.20200817173939-b72757e734f6/internal/helper/plugin/grpc_provider.go:952 +0x8ef
github.com/hashicorp/terraform-plugin-sdk/v2/internal/tfplugin5._Provider_ApplyResourceChange_Handler.func1(0x1ea3fe0, 0xc0001c2140, 0x1cab0e0, 0xc00025a0e0, 0xc0001c2140, 0x1be81c0, 0x1, 0xc0000a1320)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.0.2-0.20200817173939-b72757e734f6/internal/tfplugin5/tfplugin5.pb.go:3312 
+0x8d
github.com/hashicorp/terraform-plugin-sdk/v2/plugin.Serve.func3.1(0x1ea40a0, 0xc000154030, 0x1cab0e0, 0xc00025a0e0, 0xc0000a1300, 0xc0000a1320, 0xc000291ba0, 0x1188756, 0x1c6b3a0, 0xc000154030)1188756, 0x1c6b3a0, 0xc000154030)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.0.2-0.20200817173939-b72757e734f6/plugin/serve.go:76 +0x97                                              0660, 0xc0008143a0, 0x1ea40a0, 0xc000154030, 0xc000674000, 0x1cfb)
github.com/hashicorp/terraform-plugin-sdk/v2/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x1cc1240, 0xc000004100, 0x1ea40a0, 0xc000154030, 0xc000300660, 0xc0008143a0, 0x1ea40a0, 0xc000154030, 0xc000674000, 0x1cfb)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.0.2-0.20200817173939-b72757e734f6/internal/tfplugin5/tfplugin5.pb.go:3314 +0x152
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001fee00, 0x1eaea40, 0xc000644480, 0xc000122b00, 0xc0002815f0, 0x24bf7c0, 0x0, 0x0, 0x0)
        google.golang.org/grpc@v1.30.0/server.go:1171 +0x522
google.golang.org/grpc.(*Server).handleStream(0xc0001fee00, 0x1eaea40, 0xc000644480, 0xc000122b00, 0x0)
        google.golang.org/grpc@v1.30.0/server.go:1494 +0xce5
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000032200, 0xc0001fee00, 0x1eaea40, 0xc000644480, 0xc000122b00)
        google.golang.org/grpc@v1.30.0/server.go:834 +0xa8
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.30.0/server.go:832 +0x1fd

Error: The terraform-provider-keycloak_v3.0.1.exe 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.

I've messed around with the config and was able to narrow it down to the realm SMTP settings. It looks like if I set up the config in a way where it configures email, but then provide an empty string as values, this plugin produces the error above.

Configuration section (click to expand):
variable "smtp_from" {
  type = string
}

variable "smtp_reply_to" {
  type = string
}

variable "smtp_reply_to_display_name" {
  type    = string
  default = "My Name here"
}

variable "smtp_from_display_name" {
  type    = string
  default = "My Name here"
}

variable "smtp_host" {
  type    = string
  default   = ""
}

variable "smtp_port" {
  type    = number
  default = 587
}

variable "smtp_ssl" {
  type    = bool
  default = false
}

variable "smtp_starttls" {
  type    = bool
  default = true
}

variable "smtp_auth_password" {
  type      = string
  sensitive = true
  default   = ""
}

variable "smtp_auth_username" {
  type      = string
  sensitive = true
  default   = ""
}

resource "keycloak_realm" "my_users" {
  (...)

  smtp_server {
    envelope_from         = var.smtp_from
    from                  = var.smtp_from
    reply_to              = var.smtp_reply_to
    reply_to_display_name = var.smtp_reply_to_display_name
    from_display_name     = var.smtp_from_display_name
    host                  = var.smtp_host
    port                  = var.smtp_port
    ssl                   = var.smtp_ssl
    starttls              = var.smtp_starttls
    auth {
      password = var.smtp_auth_password
      username = var.smtp_auth_username
    }
  }

  (...)
}

While I believe this is valid Keycloak configuration (when emails are disabled), it looks like the code that sets this doesn't check for empty strings here (just took this line from the stack trace): https://github.com/mrparkers/terraform-provider-keycloak/blob/c851df424c5407726b2f448fce6c70905d9dc002/provider/resource_keycloak_realm.go#L647

@mrparkers
Copy link
Contributor

Hey @DecentM, sorry that you've run into this. This is actually a bug within the terraform plugin SDK, for which I've opened an issue here: hashicorp/terraform-plugin-sdk#216

Until that's resolved, your best bet is to not set the auth configuration at all unless both var.smtp_auth_password and var.smtp_auth_username are set. You can do that with dynamic blocks like this:

dynamic "auth" {
  for_each = var.smtp_auth_username == "" || var.smtp_auth_password == "" ? [] : [1]

  content {
    username = var.smtp_auth_username
    password = var.smtp_auth_password
  }
}

In the meantime, I'm going to close this since there is not much that can be done here outside a change in the terraform plugin SDK.

Thanks!

@DecentM
Copy link
Author

DecentM commented May 25, 2021

Thanks for the pointer, I appreciate the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants