OpenNebula / terraform-provider-opennebula

Terraform provider for OpenNebula
https://www.terraform.io/docs/providers/opennebula/
Mozilla Public License 2.0
63 stars 53 forks source link

Adding nic to VM couses plugoin crash #423

Closed evmnaumov closed 1 year ago

evmnaumov commented 1 year ago

OpenNebula Version

6.4.0.1

Terraform Version

Terraform v1.4.2 on darwin_arm64

Affected Resource(s)

Panic Output

module.vms.opennebula_virtual_machine.test: Modifying... [id=146]
╷
│ Error: Plugin did not respond
│ 
│   with module.vms.opennebula_virtual_machine.test,
│   on vms/test.tf line 1, in resource "opennebula_virtual_machine" "test":
│    1: resource "opennebula_virtual_machine" "test" {
│ 
│ 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-opennebula_v1.2.0 plugin:

panic: runtime error: index out of range [1] with length 1

goroutine 58 [running]:
github.com/OpenNebula/terraform-provider-opennebula/opennebula.updateNIC({0x1056f67a8, 0x140004c1080}, 0x1055c0b60?, {0x1055aba60?, 0x140000df200?})
        github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_virtual_machine.go:1967 +0xebc
github.com/OpenNebula/terraform-provider-opennebula/opennebula.customVirtualMachineUpdate({0x1056f67a8, 0x140004c1080}, 0x140001c8100, {0x1055aba60, 0x140000df200})
        github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_virtual_machine.go:1119 +0x60
github.com/OpenNebula/terraform-provider-opennebula/opennebula.resourceOpennebulaVirtualMachineUpdateCustom({0x1056f67a8, 0x140004c1080}, 0x140001c8100, {0x1055aba60, 0x140000df200}, 0x1056eaf88)
        github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_virtual_machine.go:1376 +0x1dec
github.com/OpenNebula/terraform-provider-opennebula/opennebula.resourceOpennebulaVirtualMachineUpdate({0x1056f67a8, 0x140004c1080}, 0x0?, {0x1055aba60, 0x140000df200})
        github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_virtual_machine.go:1106 +0x3c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x140004201c0, {0x1056f67e0, 0x140004a9d10}, 0xd?, {0x1055aba60, 0x140000df200})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:741 +0xec
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140004201c0, {0x1056f67e0, 0x140004a9d10}, 0x140004025b0, 0x1400047fd80, {0x1055aba60, 0x140000df200})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:847 +0x680
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x140003d4498, {0x1056f67e0?, 0x140004a9bf0?}, 0x140005369b0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/grpc_provider.go:1021 +0xb94
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x14000314a00, {0x1056f67e0?, 0x140004a93b0?}, 0x140001d0f50)
        github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/tf5server/server.go:818 +0x3c0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1056bc1c0?, 0x14000314a00}, {0x1056f67e0, 0x140004a93b0}, 0x140001d0ee0, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x174
google.golang.org/grpc.(*Server).processUnaryRPC(0x140003123c0, {0x1056f97e0, 0x14000003380}, 0x14000548000, 0x14000300d20, 0x105bca6a0, 0x0)
        google.golang.org/grpc@v1.50.1/server.go:1340 +0xb90
google.golang.org/grpc.(*Server).handleStream(0x140003123c0, {0x1056f97e0, 0x14000003380}, 0x14000548000, 0x0)
        google.golang.org/grpc@v1.50.1/server.go:1713 +0x840
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.50.1/server.go:965 +0x88
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.50.1/server.go:963 +0x298

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

Steps to Reproduce

  1. Create VM with one nic interface

    resource "opennebula_virtual_machine" "test" {
    name        = "test"
    description = "VM"
    cpu         = 3.6
    vcpu        = 4
    memory      = 4096
    permissions = "660"
    graphics {
    type   = "VNC"
    listen = "0.0.0.0"
    }
    
    os {
    arch = "x86_64"
    boot = "disk0"
    }
    context = {
    SET_HOSTNAME = "$NAME"
    NETWORK      = "YES"
    }
    disk {
    image_id = data.opennebula_image.debian11.id
    size     = 20480
    }
    nic {
    model           = "virtio"
    network_id      = data.opennebula_virtual_network.private.id
    }
    }
  2. Add one more nic to this VM
resource "opennebula_virtual_machine" "test" {
  name        = "test"
  description = "VM"
  cpu         = 3.6
  vcpu        = 4
  memory      = 4096
  permissions = "660"
  graphics {
    type   = "VNC"
    listen = "0.0.0.0"
  }

  os {
    arch = "x86_64"
    boot = "disk0"
  }
  context = {
    SET_HOSTNAME = "$NAME"
    NETWORK      = "YES"
  }
  disk {
    image_id = data.opennebula_image.debian11.id
    size     = 20480
  }
  nic {
    model           = "virtio"
    network_id      = data.opennebula_virtual_network.private.id
  }
+  nic {
+    model           = "virtio"
+    network_id      = data.opennebula_virtual_network.real.id
+  }

}
  1. terraform plan

    
    Terraform will perform the following actions:
    
    # module.vms.opennebula_virtual_machine.test will be updated in-place
    ~ resource "opennebula_virtual_machine" "test" {
        id                     = "146"
        name                   = "test"
        # (24 unchanged attributes hidden)
    
      + nic {
          + computed_security_groups = (known after apply)
          + model                    = "virtio"
          + network_id               = 34
        }
    
        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.



4. `terraform apply --auto-approve