This is an automated email from the ASF dual-hosted git repository.
vishesh pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/cloudstack-terraform-provider.git
The following commit(s) were added to refs/heads/main by this push:
new 9b1501e Add new key to control reatch disk to vm (#97)
9b1501e is described below
commit 9b1501e03093a3aca7e511f8d85007a75873cb69
Author: Vishesh <[email protected]>
AuthorDate: Mon Mar 11 13:53:49 2024 +0530
Add new key to control reatch disk to vm (#97)
---
cloudstack/resource_cloudstack_disk.go | 14 +++++++++++---
cloudstack/resource_cloudstack_disk_test.go | 2 +-
website/docs/r/disk.html.markdown | 3 +++
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/cloudstack/resource_cloudstack_disk.go
b/cloudstack/resource_cloudstack_disk.go
index 6127633..2453583 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 2989ae8..3d182a1 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 e87396b..1f4e052 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: