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

fix(global): nil resources #486

Merged
merged 6 commits into from
Jun 27, 2024

Conversation

danielnachtrub
Copy link
Contributor

No description provided.

@danielnachtrub danielnachtrub requested a review from a team as a code owner June 6, 2024 09:54
@danielnachtrub
Copy link
Contributor Author

Fix for empty resources, like having an input {} on routeros_routing_bgp_connection

Copy link
Collaborator

@vaerh vaerh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. This check should be centralized in the isEmpty function. Can you post an example of the resource you are having problems with?

@danielnachtrub
Copy link
Contributor Author

Sure - here's a snippet:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.routeros_routing.routeros_routing_bgp_connection.bgp_connections["backbone"] will be created
  + resource "routeros_routing_bgp_connection" "bgp_connections" {
      + add_path_out     = "none"
      + address_families = "ip"
      + as               = "65000"
      + comment          = "bgp_connection_backbone"
      + connect          = true
      + disabled         = false
      + hold_time        = (known after apply)
      + id               = (known after apply)
      + inactive         = (known after apply)
      + keepalive_time   = "3m"
      + listen           = true
      + name             = "backbone"
      + nexthop_choice   = "default"
      + routing_table    = (known after apply)
      + vrf              = "vrf_test"

      + input {}

      + local {
          + address         = "10.255.255.2"
          + default_address = (known after apply)
          + port            = 179
          + role            = "ibgp"
        }

      + output {
          + redistribute = "connected,static"
        }

      + remote {
          + address = "10.255.255.3"
          + as      = "65000"
          + port    = 179
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
╷
│ Warning: Field 'master' not found in the schema
│
│   with module.routeros_interface_vrrp[0].routeros_interface_vrrp.vrrp_interfaces["routing_backbone_vrrp"],
│   on ..\tfmodule-routeros-ethernet-interfaces\main.tf line 45, in resource "routeros_interface_vrrp" "vrrp_interfaces":
│   45: resource "routeros_interface_vrrp" "vrrp_interfaces" {
│
│ [MikrotikResourceDataToTerraform] The field was lost during the Schema development: ▷ 'master': 'true' ◁
╵
╷
│ Warning: Field 'grp_authority' not found in the schema
│
│   with module.routeros_interface_vrrp[0].routeros_interface_vrrp.vrrp_interfaces["routing_backbone_vrrp"],
│   on ..\tfmodule-routeros-ethernet-interfaces\main.tf line 45, in resource "routeros_interface_vrrp" "vrrp_interfaces":
│   45: resource "routeros_interface_vrrp" "vrrp_interfaces" {
│
│ [MikrotikResourceDataToTerraform] The field was lost during the Schema development: ▷ 'grp_authority': 'true' ◁
╵

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

module.routeros_routing.routeros_routing_bgp_connection.bgp_connections["backbone"]: Creating...
╷
│ Error: Plugin did not respond
│
│   with module.routeros_routing.routeros_routing_bgp_connection.bgp_connections["backbone"],
│   on ..\tfmodule-routeros-ip-routing\main.tf line 185, in resource "routeros_routing_bgp_connection" "bgp_connections":
│  185: resource "routeros_routing_bgp_connection" "bgp_connections" {
│
│ 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-routeros_v1.54.2.exe plugin:

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

goroutine 100 [running]:
github.com/terraform-routeros/terraform-provider-routeros/routeros.TerraformResourceDataToMikrotik(0xc00067e1d0?, 0x0?)
        github.com/terraform-routeros/terraform-provider-routeros/routeros/mikrotik_serialize.go:233 +0x17f3
github.com/terraform-routeros/terraform-provider-routeros/routeros.ResourceCreate({0x173f690, 0xc00025b180}, 0x1d11740?, 0x0?, {0x15aa8a0?, 0xc0004194a0})
        github.com/terraform-routeros/terraform-provider-routeros/routeros/resource_default_actions.go:38 +0x5d
github.com/terraform-routeros/terraform-provider-routeros/routeros.ResourceRoutingBGPConnection.DefaultCreate.func14({0x173f690?, 0xc00025b180?}, 0x0?, {0x15aa8a0?, 0xc0004194a0?})
        github.com/terraform-routeros/terraform-provider-routeros/routeros/resource_default_actions.go:212 +0x37
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0005a0c40, {0x173f5e8, 0xc0002560c0}, 0xd?, {0x15aa8a0, 0xc0004194a0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:806 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0005a0c40, {0x173f5e8, 0xc0002560c0}, 0xc0004eaf70, 0xc0002ef080, {0x15aa8a0, 0xc0004194a0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:937 +0xa89
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00038a318, {0x173f5e8?, 0xc00049bfb0?}, 0xc000419a40)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xdbc
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0002e4000, {0x173f5e8?, 0xc00049b140?}, 0xc00025a690)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x15bc6c0?, 0xc0002e4000}, {0x173f5e8, 0xc00049b140}, 0xc0002ee380, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001b1000, {0x173f5e8, 0xc00049b0b0}, {0x1743930, 0xc00022ec00}, 0xc00019b680, 0xc0001cd710, 0x1d03ef8, 0x0)
        google.golang.org/grpc@v1.63.2/server.go:1369 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc0001b1000, {0x1743930, 0xc00022ec00}, 0xc00019b680)
        google.golang.org/grpc@v1.63.2/server.go:1780 +0x1016
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 15
        google.golang.org/grpc@v1.63.2/server.go:1030 +0x135

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

@danielnachtrub danielnachtrub changed the title Fix nil resources fix(global): nil resources Jun 25, 2024
@@ -230,6 +230,11 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso

case *schema.Resource:

// skip if object is empty
if value.([]interface{})[0] == nil {
break
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the loop statement to continue

@vaerh vaerh merged commit 8571dea into terraform-routeros:main Jun 27, 2024
3 checks passed
@vaerh
Copy link
Collaborator

vaerh commented Jun 27, 2024

🎉 This PR is included in version 1.54.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@vaerh vaerh added the released label Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants