Commit 2b0ec56c authored by Yann KAISER's avatar Yann KAISER

Added instance destruction check

parent 548cc776
......@@ -13,7 +13,6 @@ import (
)
func TestAccVMInstance(t *testing.T) {
t.SkipNow()
var v vm.VMData
resource.Test(t, resource.TestCase{
IDRefreshName: "one_vm.test",
......@@ -29,6 +28,7 @@ func TestAccVMInstance(t *testing.T) {
),
},
},
CheckDestroy: testAccCheckInstanceDestroy,
})
}
......@@ -93,3 +93,33 @@ func testAccVMInstanceExists(n string, vm *vm.VMData) resource.TestCheckFunc {
return fmt.Errorf("VM instance not found")
}
}
func testAccCheckInstanceDestroy(s *terraform.State) error {
session := testAccProvider.Meta().(*Client).VMSession
for _, rs := range s.RootModule().Resources {
if rs.Type != "one_vm" {
continue
}
instanceID, err := strconv.Atoi(rs.Primary.ID)
if err != nil {
return err
}
vmData, err := session.GetVMState(instanceID)
if err != nil {
return err
}
if vmData == nil {
return nil
}
if vmData.State != vm.StateDone {
return fmt.Errorf("found unterminated vm instance with id: %d", instanceID)
}
}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment