Skip to content

Commit

Permalink
volume resize (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr authored Jan 22, 2025
1 parent ef5311a commit f02a74e
Showing 1 changed file with 45 additions and 41 deletions.
86 changes: 45 additions & 41 deletions civo/volume/resource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,52 +150,56 @@ func resourceVolumeRead(_ context.Context, d *schema.ResourceData, m interface{}
// function to update the volume
func resourceVolumeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

// apiClient := m.(*civogo.Client)
apiClient := m.(*civogo.Client)

// // overwrite the region if is define in the datasource
// if region, ok := d.GetOk("region"); ok {
// apiClient.Region = region.(string)
// }
// overwrite the region if is defined in the datasource
if region, ok := d.GetOk("region"); ok {
apiClient.Region = region.(string)
}

// log.Printf("[INFO] retrieving the volume %s", d.Id())
// resp, err := apiClient.FindVolume(d.Id())
// if err != nil {
// return fmt.Errorf("[ERR] failed retrieving the volume: %s", err)
// }
log.Printf("[INFO] retrieving the volume %s", d.Id())
resp, err := apiClient.FindVolume(d.Id())
if err != nil {
return diag.Errorf("[ERR] failed retrieving the volume: %s", err)
}

if d.HasChange("size_gb") {
return diag.Errorf("[ERR] Resize operation is not available at this moment - we are working to re-enable it soon")

/*
if resp.InstanceID != "" {
_, err := apiClient.DetachVolume(d.Id())
if err != nil {
return fmt.Errorf("[WARN] an error occurred while trying to detach volume %s, %s", d.Id(), err)
}
time.Sleep(10 * time.Second)
newSize := d.Get("size_gb").(int)
_, err = apiClient.ResizeVolume(d.Id(), newSize)
if err != nil {
return fmt.Errorf("[ERR] the volume (%s) size not change %s", d.Id(), err)
}
time.Sleep(2 * time.Second)
_, err = apiClient.AttachVolume(d.Id(), resp.InstanceID)
if err != nil {
return fmt.Errorf("[ERR] an error occurred while trying to attach the volume %s", d.Id())
}
} else {
newSize := d.Get("size_gb").(int)
_, err = apiClient.ResizeVolume(d.Id(), newSize)
if err != nil {
return fmt.Errorf("[ERR] the volume (%s) size not change %s", d.Id(), err)
}
//return diag.Errorf("[ERR] Resize operation is not available at this moment - we are working to re-enable it soon")

if resp.InstanceID != "" {
_, err := apiClient.DetachVolume(d.Id())
if err != nil {
return diag.Errorf("[WARN] an error occurred while trying to detach volume %s, %s", d.Id(), err)
}

time.Sleep(10 * time.Second)

newSize := d.Get("size_gb").(int)
_, err = apiClient.ResizeVolume(d.Id(), newSize)
if err != nil {
return diag.Errorf("[ERR] the volume (%s) size not change %s", d.Id(), err)
}
*/

time.Sleep(2 * time.Second)

attachConfig := civogo.VolumeAttachConfig{
InstanceID: resp.InstanceID,
AttachAtBoot: true,
Region: apiClient.Region,
}

_, err = apiClient.AttachVolume(d.Id(), attachConfig)
if err != nil {
return diag.Errorf("[ERR] an error occurred while trying to attach the volume %s", d.Id())
}

} else {
newSize := d.Get("size_gb").(int)
_, err = apiClient.ResizeVolume(d.Id(), newSize)
if err != nil {
return diag.Errorf("[ERR] the volume (%s) size not change %s", d.Id(), err)
}
}
}

if d.HasChange("network_id") {
Expand Down

0 comments on commit f02a74e

Please sign in to comment.