Add deletion_protection wrapper for deleting instance (#1211)

This commit is contained in:
Nick Jacques 2018-03-16 16:09:21 -05:00 committed by Nathan McKinley
parent dd79754059
commit 8ada4ffdb2
2 changed files with 17 additions and 11 deletions

View File

@ -1495,19 +1495,24 @@ func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) err
return err
}
log.Printf("[INFO] Requesting instance deletion: %s", d.Id())
op, err := config.clientCompute.Instances.Delete(project, zone, d.Id()).Do()
if err != nil {
return fmt.Errorf("Error deleting instance: %s", err)
}
// Wait for the operation to complete
opErr := computeOperationWaitTime(config.clientCompute, op, project, "instance to delete", int(d.Timeout(schema.TimeoutDelete).Minutes()))
if opErr != nil {
return opErr
}
if d.Get("deletion_protection").(bool) {
return fmt.Errorf("Cannot delete instance %s: instance Deletion Protection is enabled. Set deletion_protection to false for this resource and run \"terraform apply\" before attempting to delete it.", d.Id())
} else {
op, err := config.clientCompute.Instances.Delete(project, zone, d.Id()).Do()
if err != nil {
return fmt.Errorf("Error deleting instance: %s", err)
}
d.SetId("")
return nil
// Wait for the operation to complete
opErr := computeOperationWaitTime(config.clientCompute, op, project, "instance to delete", int(d.Timeout(schema.TimeoutDelete).Minutes()))
if opErr != nil {
return opErr
}
d.SetId("")
return nil
}
}
func resourceComputeInstanceImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {

View File

@ -91,6 +91,7 @@ The following arguments are supported:
* `description` - (Optional) A brief description of this resource.
* `deletion_protection` - (Optional) Enable deletion protection on this instance. Defaults to false.
**Note:** you must disable deletion protection before removing the resource (e.g., via `terraform destroy`), or the instance cannot be deleted and the Terraform run will not complete successfully.
* `guest_accelerator` - (Optional) List of the type and count of accelerator cards attached to the instance. Structure documented below.