NikolaLohinski / terraform-provider-freebox

🔌 A terraform provider to interact with a famous French ISP box
https://nikolalohinski.github.io/terraform-provider-freebox
2 stars 2 forks source link

Bug: Auto remove deleted VM #6

Open holyhope opened 1 day ago

holyhope commented 1 day ago

Hello,

In my opinion, the terraform provider should reconcile its state when the VM no more exist.

Expected behavior

The provider should apply the specified resources, either it exist or not.

Current behavior

The provider fails when the resource no more exist.

Steps to reproduce

  1. Create a VM with terraform.
  2. Delete the VM from the FreeboxOS UI.
  3. Apply again with terraform.

    Planning failed. Terraform encountered an error while generating this plan.
    
    ╷
    │ Error: Failed to get virtual machine
    │ 
    │   with freebox_virtual_machine.server,
    │   on deploy.tf line 6, in resource "freebox_virtual_machine" "server":
    │    6: resource "freebox_virtual_machine" "server" {
    │ 
    │ virtual machine not found
NikolaLohinski commented 19 hours ago

Hi @holyhope

I see your point, but it is not expected of the VM resource to vanish when managed via terraform.

If the remote state changes, the provider should definitely try to reconcile, but if the remote state is non-existent (could be for plenty of reasons, e.g the vm got deleted, the state got edited manually, etc...), it's an error case. Moreover, I am not even sure there's anything we can do about it, as the resource lifecycle is not managed by the provider but by terraform itself. The provider just defines basic CRUD operators, and if the read is failing because the resource is not there, there's nothing in terraform to create it on the fly AFAIK.

Hope it's understandable