Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions cloudstack/resource_cloudstack_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func resourceCloudStackDisk() *schema.Resource {
Computed: true,
},

"expunge": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"tags": tagsSchema(),
},
}
Expand Down Expand Up @@ -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, "+
Expand Down
7 changes: 6 additions & 1 deletion cloudstack/resource_cloudstack_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
})
Expand Down Expand Up @@ -246,6 +246,7 @@ resource "cloudstack_disk" "foo" {
attach = false
disk_offering = "Small"
zone = "Sandbox-simulator"
expunge = true
Comment thread
bddvlpr marked this conversation as resolved.
tags = {
terraform-tag = "true"
}
Expand All @@ -256,13 +257,15 @@ resource "cloudstack_disk" "foo" {
name = "terraform-disk"
disk_offering = "Small"
zone = "Sandbox-simulator"
expunge = true
}`

const testAccCloudStackDisk_resize = `
resource "cloudstack_disk" "foo" {
name = "terraform-disk"
disk_offering = "Medium"
zone = "Sandbox-simulator"
expunge = true
}`

const testAccCloudStackDisk_deviceID = `
Expand Down Expand Up @@ -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 = `
Expand All @@ -300,6 +304,7 @@ resource "cloudstack_disk" "foo" {
disk_offering = "Small"
zone = "Sandbox-simulator"
delete_protection = %t
expunge = true
tags = {
terraform-tag = "true"
}
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading