vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
150 stars 32 forks source link

Deleted VM causes provider to error rather than recreate the resource #88

Closed ddelnano closed 3 years ago

ddelnano commented 3 years ago

When a VM is destroyed but still exists in the statefile the provider will show the following error

ddelnano@ddelnano-desktop:~/code/terraform/xolab$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.xenorchestra_pool.pool: Refreshing state... [id=355ee47d-ff4c-4924-3db2-fd86ae629676]
data.xenorchestra_template.vm_template: Refreshing state... [id=08701be4-52f0-c201-a208-16e765d33e5e]
data.xenorchestra_sr.sr: Refreshing state... [id=86a9757d-9c05-9fe0-e79a-8243cb1f37f3]
data.xenorchestra_network.network: Refreshing state... [id=a12df741-f34f-7d05-f120-462f0ab39a48]
xenorchestra_vm.vm: Refreshing state... [id=758f81c5-2cc9-e5ff-e865-83a9880b6916]

Error: Could not find client.Vm with query: {Type: Id:758f81c5-2cc9-e5ff-e865-83a9880b6916 NameDescription: NameLabel: CPUs:{Number:0} Memory:{Dynamic:[] Static:[] Size:0} PowerState: VIFs:[] VirtualizationMode: PoolId: Template: AutoPoweron:false HA: CloudConfig: ResourceSet:}

ddelnano@ddelnano-desktop:~/code/terraform/xolab$ ls
crash.log  provider.tf  resource-set.pcap  template.tf  terraform.tfstate  terraform.tfstate.1602781045.backup  terraform.tfstate.backup
ddelnano@ddelnano-desktop:~/code/terraform/xolab$ terraform state list
data.xenorchestra_network.network
data.xenorchestra_pool.pool
data.xenorchestra_sr.sr
data.xenorchestra_template.vm_template
xenorchestra_vm.vm
ddelnano@ddelnano-desktop:~/code/terraform/xolab$ terraform state show xenorchestra_vm.vm
# xenorchestra_vm.vm:
resource "xenorchestra_vm" "vm" {
    auto_poweron = false
    core_os      = false
    cpu_cap      = 0
    cpu_weight   = 0
    cpus         = 1
    id           = "758f81c5-2cc9-e5ff-e865-83a9880b6916"
    memory_max   = 2147467264
    name_label   = "XO terraform tutorial"
    resource_set = "70COTIDuNHg"
    template     = "08701be4-52f0-c201-a208-16e765d33e5e"

    disk {
        name_label = "VM root volume"
        size       = 50212254720
        sr_id      = "86a9757d-9c05-9fe0-e79a-8243cb1f37f3"
    }

    network {
        attached    = true
        device      = "0"
        mac_address = "9a:d3:29:04:96:90"
        network_id  = "a12df741-f34f-7d05-f120-462f0ab39a48"
    }
}

The expected behavior is that the provider will realize the resource is missing and will attempt to recreate it.

ddelnano commented 3 years ago

I validated that this isn't the case on the latest version of the provider (v0.15.0) and also that there is an acceptance test that was written before this issue that should prevent this. So I'm not sure how this happened, closing. It can be investigated more if there are future occurrences of it.