Skip to content

Commit

Permalink
Merge pull request #144 from yannickstruyf3/fix-#143
Browse files Browse the repository at this point in the history
fix issue 143: …
  • Loading branch information
PacoDw authored Jun 19, 2020
2 parents 4a0562b + b1d80f1 commit 8f2d6bb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,13 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("error reading Virtual Machine %s: %s", d.Id(), err)
}

// Added check for deletion. Re-running TF right after VM deletion, can cause an error because the ID is still present in API.
// Check if name is not present and also resources is not present
if resp.Status.Name == nil && resp.Status.Resources == nil {
d.SetId("")
return nil
}

if err := flattenClusterReference(resp.Status.ClusterReference, d); err != nil {
return fmt.Errorf("error setting cluster information for Virtual Machine %s: %s", d.Id(), err)
}
Expand Down Expand Up @@ -1463,11 +1470,13 @@ func resourceNutanixVirtualMachineExists(d *schema.ResourceData, meta interface{
conn := meta.(*Client).API

_, err := conn.V3.GetVM(d.Id())

if err != nil {
return false, err
if strings.Contains(fmt.Sprint(err), "ENTITY_NOT_FOUND") {
d.SetId("")
return false, nil
}
return false, fmt.Errorf("error checking virtual Virtual Machine %s existence: %s", d.Id(), err)
}

return true, nil
}

Expand Down

0 comments on commit 8f2d6bb

Please sign in to comment.