Skip to content

Commit 2860a96

Browse files
committed
Add new key to control reatch disk to vm
1 parent e5955fd commit 2860a96

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

cloudstack/resource_cloudstack_disk.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ func resourceCloudStackDisk() *schema.Resource {
9393
},
9494

9595
"tags": tagsSchema(),
96+
97+
"reattach_on_change": {
98+
Type: schema.TypeBool,
99+
Optional: true,
100+
Default: false,
101+
},
96102
},
97103
}
98104
}
@@ -216,9 +222,11 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro
216222
name := d.Get("name").(string)
217223

218224
if d.HasChange("disk_offering") || d.HasChange("size") {
219-
// Detach the volume (re-attach is done at the end of this function)
220-
if err := resourceCloudStackDiskDetach(d, meta); err != nil {
221-
return fmt.Errorf("Error detaching disk %s from virtual machine: %s", name, err)
225+
if d.Get("reattach_on_change").(bool) {
226+
// Detach the volume (re-attach is done at the end of this function)
227+
if err := resourceCloudStackDiskDetach(d, meta); err != nil {
228+
return fmt.Errorf("Error detaching disk %s from virtual machine: %s", name, err)
229+
}
222230
}
223231

224232
// Create a new parameter struct

cloudstack/resource_cloudstack_disk_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func TestAccCloudStackDisk_import(t *testing.T) {
116116
ResourceName: "cloudstack_disk.foo",
117117
ImportState: true,
118118
ImportStateVerify: true,
119-
ImportStateVerifyIgnore: []string{"shrink_ok"},
119+
ImportStateVerifyIgnore: []string{"shrink_ok", "reattach_on_change"},
120120
},
121121
},
122122
})

website/docs/r/disk.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ The following arguments are supported:
5353
* `zone` - (Required) The name or ID of the zone where this disk volume will be available.
5454
Changing this forces a new resource to be created.
5555

56+
* `reattach_on_change` - (Optional) Determines whether or not to detach the disk volume
57+
from the virtual machine on disk offering or size change.
58+
5659
## Attributes Reference
5760

5861
The following attributes are exported:

0 commit comments

Comments
 (0)