diff --git a/cloudstack/resource_cloudstack_disk.go b/cloudstack/resource_cloudstack_disk.go index 61276334..24535835 100644 --- a/cloudstack/resource_cloudstack_disk.go +++ b/cloudstack/resource_cloudstack_disk.go @@ -93,6 +93,12 @@ func resourceCloudStackDisk() *schema.Resource { }, "tags": tagsSchema(), + + "reattach_on_change": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, } } @@ -216,9 +222,11 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro name := d.Get("name").(string) if d.HasChange("disk_offering") || d.HasChange("size") { - // Detach the volume (re-attach is done at the end of this function) - if err := resourceCloudStackDiskDetach(d, meta); err != nil { - return fmt.Errorf("Error detaching disk %s from virtual machine: %s", name, err) + if d.Get("reattach_on_change").(bool) { + // Detach the volume (re-attach is done at the end of this function) + if err := resourceCloudStackDiskDetach(d, meta); err != nil { + return fmt.Errorf("Error detaching disk %s from virtual machine: %s", name, err) + } } // Create a new parameter struct diff --git a/cloudstack/resource_cloudstack_disk_test.go b/cloudstack/resource_cloudstack_disk_test.go index 2989ae87..3d182a12 100644 --- a/cloudstack/resource_cloudstack_disk_test.go +++ b/cloudstack/resource_cloudstack_disk_test.go @@ -116,7 +116,7 @@ func TestAccCloudStackDisk_import(t *testing.T) { ResourceName: "cloudstack_disk.foo", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"shrink_ok"}, + ImportStateVerifyIgnore: []string{"shrink_ok", "reattach_on_change"}, }, }, }) diff --git a/website/docs/r/disk.html.markdown b/website/docs/r/disk.html.markdown index e87396b4..1f4e0528 100644 --- a/website/docs/r/disk.html.markdown +++ b/website/docs/r/disk.html.markdown @@ -53,6 +53,9 @@ The following arguments are supported: * `zone` - (Required) The name or ID of the zone where this disk volume will be available. Changing this forces a new resource to be created. +* `reattach_on_change` - (Optional) Determines whether or not to detach the disk volume + from the virtual machine on disk offering or size change. + ## Attributes Reference The following attributes are exported: