dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.54k stars 457 forks source link

Plugin fail when providing IDs with only one caracter #936

Open cafsenra opened 2 years ago

cafsenra commented 2 years ago

username@hostname:~/qemu-provider$ sudo virsh list
 Id    Name                           State
----------------------------------------------------
 2     ac5a5113-ec21-40cc-b038-abb2aa1b6738 running

username@hostname:~/qemu-provider$ sudo terraform import libvirt_pool.gitlab 2
libvirt_pool.gitlab: Importing from ID "2"...
libvirt_pool.gitlab: Import prepared!
  Prepared libvirt_pool for import
libvirt_pool.gitlab: Refreshing state... [id=2]
╷
│ Error: Request cancelled
│ 
│ The plugin.(*GRPCProvider).ReadResource request was cancelled.
╵

Stack trace from the terraform-provider-libvirt_v0.6.14 plugin:

panic: uuid: Parse(2): invalid UUID length: 1

goroutine 38 [running]:
github.com/google/uuid.MustParse({0x14f0610, 0x1})
        github.com/google/uuid@v1.1.2/uuid.go:142 +0xb9
github.com/dmacvicar/terraform-provider-libvirt/libvirt.parseUUID(...)
        github.com/dmacvicar/terraform-provider-libvirt/libvirt/utils_libvirt.go:11
github.com/dmacvicar/terraform-provider-libvirt/libvirt.resourceLibvirtPoolExists(0xc0005be310, {0xc8f8e0, 0xc00000db78})
        github.com/dmacvicar/terraform-provider-libvirt/libvirt/resource_libvirt_pool.go:249 +0x1f1
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000413440, 0xc0005ba5a0, {0xc8f8e0, 0xc00000db78})
        github.com/hashicorp/terraform-plugin-sdk@v1.9.0/helper/schema/resource.go:445 +0x131
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc00000ec70, {0xc0000709c0, 0x516766}, 0xc0000709c0)
        github.com/hashicorp/terraform-plugin-sdk@v1.9.0/internal/helper/plugin/grpc_provider.go:525 +0x34b
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler({0xdf5140, 0xc00000ec70}, {0xfb64b0, 0xc0005ad860}, 0xc000070960, 0x0)
        github.com/hashicorp/terraform-plugin-sdk@v1.9.0/internal/tfplugin5/tfplugin5.pb.go:3269 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00017a780, {0xfc3c00, 0xc00017a180}, 0xc0000a0600, 0xc0004e5590, 0x155bf50, 0x0)
        google.golang.org/grpc@v1.27.1/server.go:1024 +0xd1e
google.golang.org/grpc.(*Server).handleStream(0xc00017a780, {0xfc3c00, 0xc00017a180}, 0xc0000a0600, 0x0)
        google.golang.org/grpc@v1.27.1/server.go:1313 +0xa56
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/grpc@v1.27.1/server.go:722 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.27.1/server.go:720 +0xef

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

Info about VM:

username@hostname:~/qemu-provider$ sudo virsh dominfo ac5a5113-ec21-40cc-b038-abb2aa1b6738
Id:             2
Name:           ac5a5113-ec21-40cc-b038-abb2aa1b6738
UUID:           ac5a5113-ec21-40cc-b038-abb2aa1b6738
OS Type:        hvm
State:          running
CPU(s):         2
CPU time:       124201.8s
Max memory:     4194304 KiB
Used memory:    4194304 KiB
Persistent:     no
Autostart:      disable
Managed save:   no
Security model: none
Security DOI:   0
stijn-acc commented 1 year ago

Hi @cafsenra,

Try running the "terraform import" command but using the UUID of the domain you are trying to import. So in your case, something like username@hostname:~/qemu-provider$ sudo terraform import libvirt_pool.gitlab ac5a5113-ec21-40cc-b038-abb2aa1b6738