Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new key to control reattach disk to vm #97

Merged
merged 1 commit into from
Mar 11, 2024
Merged
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
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
Loading