Skip to content

Commit

Permalink
Add new key to control reatch disk to vm (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishesh92 committed Mar 11, 2024
1 parent e607951 commit 9b1501e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
14 changes: 11 additions & 3 deletions cloudstack/resource_cloudstack_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func resourceCloudStackDisk() *schema.Resource {
},

"tags": tagsSchema(),

"reattach_on_change": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/resource_cloudstack_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
})
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 @@ -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:
Expand Down

0 comments on commit 9b1501e

Please sign in to comment.