equinix / terraform-provider-metal

DEPRECATED Equinix Metal standalone TF provider. Use the unified Equinix Terraform Provider.
https://registry.terraform.io/providers/equinix/equinix/latest/docs/guides/migration_guide_equinix_metal
Mozilla Public License 2.0
14 stars 11 forks source link

deleting a device from a hardware reservation fails #199

Closed displague closed 2 years ago

displague commented 2 years ago

Deleting a device created from a hardware reservation fails when wait_for_reservation_deprovision = "true" is set.

https://github.com/equinix/terraform-provider-metal/blob/main/metal/resource_metal_device.go#L781

The deployed_hardware_reservation_id should be used rather than the hardware_reservation_id.

As a fall-back, if deployed_hardware_reservation_id is not set, we could consider deleting by hardware_reservation_id so long as it is not set to next-available. If implemented, this would need to be prepared for a 404. One reason not to implement this fall-back behavior is that a reservation consumed outside of this TF config could be incorrectly deleted. Users wanting to clean up a metal_device that lacks deployed_hardware_reservation_id in this case should import the metal_device (consuming the reservation) first, before attempting to delete it.

displague commented 2 years ago

It would be helpful to test device deletion with reservations to prevent this in the future. The resources for doing so in E2E testing would incur costly and parallelization constraints. A mock creation and deletion could be beneficial for testing this behavior.

displague commented 2 years ago

The tell-tale logging sign that this bug is being encountered is:

GET /metal/v1/hardware-reservations/next-available HTTP/1.1
│ Error: Not found
enkelprifti98 commented 2 years ago

Just want to clarify here that this issue only happens when wait_for_reservation_deprovision = "true" is set for a metal_device resource. Otherwise deleting reserved instances works fine.

displague commented 2 years ago

thanks @enkelprifti98 - I updated the description.

t0mk commented 2 years ago

@displague @enkelprifti98 I will take a look.

displague commented 2 years ago

Fix released in v3.2.1