OpenNebula / terraform-provider-opennebula

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

Plugin crashes when trying to decrease virtual machine's raw disk size #500

Open rovilu opened 11 months ago

rovilu commented 11 months ago

Description

There is a possibility to add volatile disk to opennebula_virtual_machine resource, which shares the virtual machine's lifecycle. The documentation says that if size disk size value is changed on an existing resource, it must be bigger than the previous one.

If the new value is still smaller than the previous one, on "terraform apply", the plugin crashes producing a huge error log:

Stack trace from the terraform-provider-opennebula_v1.3.0 plugin:

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

goroutine 113 [running]: github.com/OpenNebula/terraform-provider-opennebula/opennebula.updateDisk({0xe86ba8, 0xc0003067e0}, 0xc000163dc0?, {0xc44800?, 0xc000163dc0?}) github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_virtual_machine.go:1724 +0x19b3 github.com/OpenNebula/terraform-provider-opennebula/opennebula.resourceOpennebulaVirtualMachineUpdateCustom({0xe86ba8, 0xc0003067e0}, 0xc00004c100, {0xc44800, 0xc000163dc0}, 0xd93038) github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_virtual_machine.go:1321 +0x2195 github.com/OpenNebula/terraform-provider-opennebula/opennebula.resourceOpennebulaVirtualMachineUpdate({0xe86ba8, 0xc0003067e0}, 0x0?, {0xc44800, 0xc000163dc0}) github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_virtual_machine.go:1101 +0x39 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).update(0xc000488540, {0xe86be0, 0xc000889bf0}, 0xd?, {0xc44800, 0xc000163dc0}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:741 +0x12e github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).Apply(0xc000488540, {0xe86be0, 0xc000889bf0}, 0xc00071a8f0, 0xc00004d600, {0xc44800, 0xc000163dc0}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:847 +0x82c github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(GRPCProviderServer).ApplyResourceChange(0xc000223758, {0xe86be0?, 0xc000889ad0?}, 0xc000528730) github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/grpc_provider.go:1021 +0xe3c github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(server).ApplyResourceChange(0xc0003710e0, {0xe86be0?, 0xc0008892c0?}, 0xc00014c310) github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/tf5server/server.go:818 +0x574 github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xd08360?, 0xc0003710e0}, {0xe86be0, 0xc0008892c0}, 0xc00014c2a0, 0x0) github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170 google.golang.org/grpc.(Server).processUnaryRPC(0xc0003783c0, {0xe89de0, 0xc00050a1a0}, 0xc00040c5a0, 0xc0004a25a0, 0x13766c0, 0x0) google.golang.org/grpc@v1.50.1/server.go:1340 +0xd13 google.golang.org/grpc.(Server).handleStream(0xc0003783c0, {0xe89de0, 0xc00050a1a0}, 0xc00040c5a0, 0x0) google.golang.org/grpc@v1.50.1/server.go:1713 +0xa1b google.golang.org/grpc.(Server).serveStreams.func1.2() google.golang.org/grpc@v1.50.1/server.go:965 +0x98 created by google.golang.org/grpc.(Server).serveStreams.func1 google.golang.org/grpc@v1.50.1/server.go:963 +0x28a

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

Terraform and Provider version

Terraform v1.6.2 OpenNebula provider v1.3.0

Affected resources and data sources

opennebula_virtual_machine

Terraform configuration

No response

Expected behavior

Error is raised by the plugin telling that the disk size value should be bigger than the previous one.

Actual behavior

The plugin crashes.

Steps to Reproduce

  1. Create "opennebula_virtual_machine" resource with raw disk of a random size, e.g. using sample:

    
    resource "opennebula_virtual_machine" "test" {
    ....
    
    disk {
    size            = 10240
    driver          = "raw"
    dev_prefix      = "sd"
    volatile_type   = "fs"
    volatile_format = "raw"
    }

....

2. Create the virtual machine (`terraform plan; terraform apply`)
3. Change the "size" parameter value in the "disk" block to the smaller one, e.g.

.... disk { size = 5120 driver = "raw" dev_prefix = "sd" volatile_type = "fs" volatile_format = "raw" } .....


4. Apply changes (`terraform plan; terraform apply`) (multiple times if needed)
5. Enjoy the errors.

### Debug output

_No response_

### Panic output

_No response_

### Important factoids

_No response_

### References

_No response_
github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 30 days with no activity and it has not the 'status: confirmed' label or it is not in a milestone. Remove the 'status: stale' label or comment, or this will be closed in 5 days.

rovilu commented 10 months ago

Up

github-actions[bot] commented 9 months ago

This issue is stale because it has been open for 30 days with no activity and it has not the 'status: confirmed' label or it is not in a milestone. Remove the 'status: stale' label or comment, or this will be closed in 5 days.

treywelsh commented 3 months ago

I think it would be better to fix this at the same time we externalize the disk resource as it's not a critical bug

525