diff --git a/cloudstack/resource_cloudstack_disk.go b/cloudstack/resource_cloudstack_disk.go index 8a1c5529..07d6c03a 100644 --- a/cloudstack/resource_cloudstack_disk.go +++ b/cloudstack/resource_cloudstack_disk.go @@ -104,6 +104,12 @@ func resourceCloudStackDisk() *schema.Resource { Computed: true, }, + "expunge": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "tags": tagsSchema(), }, } @@ -323,10 +329,14 @@ func resourceCloudStackDiskDelete(d *schema.ResourceData, meta interface{}) erro } // Create a new parameter struct - p := cs.Volume.NewDeleteVolumeParams(d.Id()) + p := cs.Volume.NewDestroyVolumeParams(d.Id()) + + if d.Get("expunge").(bool) { + p.SetExpunge(true) + } - // Delete the voluem - if _, err := cs.Volume.DeleteVolume(p); err != nil { + // Destroy the volume + if _, err := cs.Volume.DestroyVolume(p); err != nil { // This is a very poor way to be told the ID does no longer exist :( if strings.Contains(err.Error(), fmt.Sprintf( "Invalid parameter id value=%s due to incorrect long value format, "+ diff --git a/cloudstack/resource_cloudstack_disk_test.go b/cloudstack/resource_cloudstack_disk_test.go index 6fc04614..24595cd9 100644 --- a/cloudstack/resource_cloudstack_disk_test.go +++ b/cloudstack/resource_cloudstack_disk_test.go @@ -117,7 +117,7 @@ func TestAccCloudStackDisk_import(t *testing.T) { ResourceName: "cloudstack_disk.foo", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"shrink_ok", "reattach_on_change"}, + ImportStateVerifyIgnore: []string{"expunge", "shrink_ok", "reattach_on_change"}, }, }, }) @@ -246,6 +246,7 @@ resource "cloudstack_disk" "foo" { attach = false disk_offering = "Small" zone = "Sandbox-simulator" + expunge = true tags = { terraform-tag = "true" } @@ -256,6 +257,7 @@ resource "cloudstack_disk" "foo" { name = "terraform-disk" disk_offering = "Small" zone = "Sandbox-simulator" + expunge = true }` const testAccCloudStackDisk_resize = ` @@ -263,6 +265,7 @@ resource "cloudstack_disk" "foo" { name = "terraform-disk" disk_offering = "Medium" zone = "Sandbox-simulator" + expunge = true }` const testAccCloudStackDisk_deviceID = ` @@ -291,6 +294,7 @@ resource "cloudstack_disk" "foo" { disk_offering = "Small" virtual_machine_id = cloudstack_instance.foobar.id zone = cloudstack_instance.foobar.zone + expunge = true }` const testAccCloudStackDisk_deleteProtection = ` @@ -300,6 +304,7 @@ resource "cloudstack_disk" "foo" { disk_offering = "Small" zone = "Sandbox-simulator" delete_protection = %t + expunge = true tags = { terraform-tag = "true" } diff --git a/website/docs/r/disk.html.markdown b/website/docs/r/disk.html.markdown index 05d2dfb7..9db8bbcd 100644 --- a/website/docs/r/disk.html.markdown +++ b/website/docs/r/disk.html.markdown @@ -59,6 +59,9 @@ The following arguments are supported: * `delete_protection` - (Optional) Set delete protection for the volume. If true, the volume will be protected from deletion. Note: If the volume is managed by another service like autoscaling groups or CKS, delete protection will be ignored. +* `expunge` - (Optional) This determines if the disk volume is expunged when it is + destroyed (defaults false). + ## Attributes Reference The following attributes are exported: