provider/openstack: Force Deletion of Instances (#12689)
This commit adds the `force_delete` argument, enabling instances to be forcefully deleted.
This commit is contained in:
parent
ad12d8804b
commit
9683f705f7
|
@ -324,6 +324,11 @@ func resourceComputeInstanceV2() *schema.Resource {
|
|||
Optional: true,
|
||||
Default: false,
|
||||
},
|
||||
"force_delete": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -882,10 +887,19 @@ func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) e
|
|||
}
|
||||
}
|
||||
|
||||
if d.Get("force_delete").(bool) {
|
||||
log.Printf("[DEBUG] Force deleting OpenStack Instance %s", d.Id())
|
||||
err = servers.ForceDelete(computeClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack server: %s", err)
|
||||
}
|
||||
} else {
|
||||
log.Printf("[DEBUG] Deleting OpenStack Instance %s", d.Id())
|
||||
err = servers.Delete(computeClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack server: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for the instance to delete before moving on.
|
||||
log.Printf("[DEBUG] Waiting for instance (%s) to delete", d.Id())
|
||||
|
|
|
@ -622,6 +622,23 @@ func TestAccComputeV2Instance_metadataRemove(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccComputeV2Instance_forceDelete(t *testing.T) {
|
||||
var instance servers.Server
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeV2InstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeV2Instance_forceDelete,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error {
|
||||
config := testAccProvider.Meta().(*Config)
|
||||
computeClient, err := config.computeV2Client(OS_REGION_NAME)
|
||||
|
@ -1515,3 +1532,11 @@ resource "openstack_compute_instance_v2" "instance_1" {
|
|||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testAccComputeV2Instance_forceDelete = `
|
||||
resource "openstack_compute_instance_v2" "instance_1" {
|
||||
name = "instance_1"
|
||||
security_groups = ["default"]
|
||||
force_delete = true
|
||||
}
|
||||
`
|
||||
|
|
|
@ -337,6 +337,10 @@ The following arguments are supported:
|
|||
before destroying it, thus giving chance for guest OS daemons to stop correctly.
|
||||
If instance doesn't stop within timeout, it will be destroyed anyway.
|
||||
|
||||
* `force_delete` - (Optional) Whether to force the OpenStack instance to be
|
||||
forcefully deleted. This is useful for environments that have reclaim / soft
|
||||
deletion enabled.
|
||||
|
||||
|
||||
The `network` block supports:
|
||||
|
||||
|
|
Loading…
Reference in New Issue