From bd6260aa3e02511efde7584168acf0f7c64cb433 Mon Sep 17 00:00:00 2001 From: 4censord Date: Fri, 9 Dec 2022 14:38:22 +0100 Subject: [PATCH] Only try to shutdown VM if running As discussed in https://github.com/terra-farm/terraform-provider-xenorchestra/pull/212 Trying to stop a VM that is not running results in an error, so we only do shutdowns for running VMs now Possible power-states are "Running, Halted, Paused, Suspended" --- xoa/resource_xenorchestra_vm.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xoa/resource_xenorchestra_vm.go b/xoa/resource_xenorchestra_vm.go index 997d9427..2f809d48 100644 --- a/xoa/resource_xenorchestra_vm.go +++ b/xoa/resource_xenorchestra_vm.go @@ -836,10 +836,19 @@ func resourceVmDelete(d *schema.ResourceData, m interface{}) error { vmReq := client.Vm{ Id: d.Id(), } - err := c.HaltVm(vmReq) + + vm, err := c.GetVm(vmReq) if err != nil { return err } + + if vm.PowerState == "Running" { + err = c.HaltVm(vmReq) + if err != nil { + return err + } + } + err = c.DeleteVm(d.Id()) if err != nil { return err