dalet-oss / terraform-provider-opnsense

Terraform Provider for OPNSense DHCP Leases
Apache License 2.0
30 stars 6 forks source link

Plugin crashing: invalid memory address or nil pointer dereference #7

Open Lokechu opened 1 year ago

Lokechu commented 1 year ago

System Information

MacOS 13.2.1 (Ventura) darwin_arm64

Terraform version

v1.4.4

Provider versions

v0.3.1

OPNsense versions (but I don't think it is even making it this far)

OPNsense 23.1.5_4-amd64 FreeBSD 13.1-RELEASE-p7 OpenSSL 1.1.1t 7 Feb 2023


Description of Issue/Question

Plugin is crashing when trying to run terraform apply to create a static dhcp lease.

Setup

variable "dhcp_static_leases" { type = map(map(string)) default = { test = { interface = "LAN", mac = "00:11:22:33:44:55", ipaddr = "192.168.187.45" } } }

resource "opnsense_dhcp_static_map" "misc_static" { for_each = var.dhcp_static_leases hostname = each.key interface = each.value.interface mac = each.value.mac ipaddr = each.value.ipaddr }

Steps to Reproduce Issue

Try to create any static lease. Plugin crashes with memory error upon terraform apply.


Additional information:

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-opnsense plugin:

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

goroutine 14 [running]: github.com/gxben/terraform-provider-opnsense/opnsense.(DHCPSession).GetStaticFieldNames(0x1400007f2c0, 0x140003809e0?, 0xa56?) /Users/loki/.local/share/terraform.d/plugins/terraform-provider-opnsense/opnsense/dhcp.go:69 +0xc4 github.com/gxben/terraform-provider-opnsense/opnsense.(DHCPSession).GetAllInterfaceStaticMappings(0x1400007f2c0, {0x1400048d0e9, 0x3}) /Users/loki/.local/share/terraform.d/plugins/terraform-provider-opnsense/opnsense/dhcp.go:146 +0x1f4 github.com/gxben/terraform-provider-opnsense/opnsense.(DHCPSession).FindMappingByMAC(0x1400007f2c0, 0x140005eb668) /Users/loki/.local/share/terraform.d/plugins/terraform-provider-opnsense/opnsense/dhcp.go:249 +0x30 github.com/gxben/terraform-provider-opnsense/opnsense.(DHCPSession).CreateStaticMapping(0x1400007f2c0, 0x140005eb668) /Users/loki/.local/share/terraform.d/plugins/terraform-provider-opnsense/opnsense/dhcp.go:268 +0x24 github.com/gxben/terraform-provider-opnsense/opnsense.resourceDhcpStaticMappingCreate(0x1036a61a0?, {0x103645980?, 0x14000019a40}) /Users/loki/.local/share/terraform.d/plugins/terraform-provider-opnsense/opnsense/resource_opn_dhcp_static_map.go:89 +0x1fc github.com/hashicorp/terraform-plugin-sdk/helper/schema.(Resource).Apply(0x140004b2360, 0x1400004d9a0, 0x140003806a0, {0x103645980, 0x14000019a40}) /Users/loki/.local/share/rtx/installs/go/1.20.3/packages/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.9.0/helper/schema/resource.go:310 +0x3dc github.com/hashicorp/terraform-plugin-sdk/helper/schema.(Provider).Apply(0x14000181f80, 0x140005eb940, 0x103473c30?, 0xf?) /Users/loki/.local/share/rtx/installs/go/1.20.3/packages/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.9.0/helper/schema/provider.go:294 +0x6c github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(GRPCProviderServer).ApplyResourceChange(0x1400000ebb0, {0x14000502150?, 0x14000386840?}, 0x14000502150) /Users/loki/.local/share/rtx/installs/go/1.20.3/packages/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.9.0/internal/helper/plugin/grpc_provider.go:885 +0x6a8 github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x10376cce0?, 0x1400000ebb0}, {0x1037a2258, 0x140005e2060}, 0x14000386840, 0x0) /Users/loki/.local/share/rtx/installs/go/1.20.3/packages/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.9.0/internal/tfplugin5/tfplugin5.pb.go:3305 +0x170 google.golang.org/grpc.(Server).processUnaryRPC(0x140001a6480, {0x1037a5d40, 0x1400017e000}, 0x140001ac300, 0x14000383770, 0x103d38500, 0x0) /Users/loki/.local/share/rtx/installs/go/1.20.3/packages/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:1024 +0xb8c google.golang.org/grpc.(Server).handleStream(0x140001a6480, {0x1037a5d40, 0x1400017e000}, 0x140001ac300, 0x0) /Users/loki/.local/share/rtx/installs/go/1.20.3/packages/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:1313 +0x88c google.golang.org/grpc.(Server).serveStreams.func1.1() /Users/loki/.local/share/rtx/installs/go/1.20.3/packages/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:722 +0x84 created by google.golang.org/grpc.(*Server).serveStreams.func1 /Users/loki/.local/share/rtx/installs/go/1.20.3/packages/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:720 +0xe8

Error: The terraform-provider-opnsense 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.

dedene commented 1 year ago

I was having the same issue at first when using an OPNSense user without the proper permissions.

For the DHCP reservations resource, it seems you need at least: