Skip to content

Commit df75afa

Browse files
committed
volume resize
1 parent ef5311a commit df75afa

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

Diff for: civo/volume/resource_volume.go

+45-41
Original file line numberDiff line numberDiff line change
@@ -150,52 +150,56 @@ func resourceVolumeRead(_ context.Context, d *schema.ResourceData, m interface{}
150150
// function to update the volume
151151
func resourceVolumeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
152152

153-
// apiClient := m.(*civogo.Client)
153+
apiClient := m.(*civogo.Client)
154154

155-
// // overwrite the region if is define in the datasource
156-
// if region, ok := d.GetOk("region"); ok {
157-
// apiClient.Region = region.(string)
158-
// }
155+
// overwrite the region if is defined in the datasource
156+
if region, ok := d.GetOk("region"); ok {
157+
apiClient.Region = region.(string)
158+
}
159159

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

166166
if d.HasChange("size_gb") {
167-
return diag.Errorf("[ERR] Resize operation is not available at this moment - we are working to re-enable it soon")
168-
169-
/*
170-
if resp.InstanceID != "" {
171-
_, err := apiClient.DetachVolume(d.Id())
172-
if err != nil {
173-
return fmt.Errorf("[WARN] an error occurred while trying to detach volume %s, %s", d.Id(), err)
174-
}
175-
176-
time.Sleep(10 * time.Second)
177-
178-
newSize := d.Get("size_gb").(int)
179-
_, err = apiClient.ResizeVolume(d.Id(), newSize)
180-
if err != nil {
181-
return fmt.Errorf("[ERR] the volume (%s) size not change %s", d.Id(), err)
182-
}
183-
184-
time.Sleep(2 * time.Second)
185-
186-
_, err = apiClient.AttachVolume(d.Id(), resp.InstanceID)
187-
if err != nil {
188-
return fmt.Errorf("[ERR] an error occurred while trying to attach the volume %s", d.Id())
189-
}
190-
191-
} else {
192-
newSize := d.Get("size_gb").(int)
193-
_, err = apiClient.ResizeVolume(d.Id(), newSize)
194-
if err != nil {
195-
return fmt.Errorf("[ERR] the volume (%s) size not change %s", d.Id(), err)
196-
}
167+
//return diag.Errorf("[ERR] Resize operation is not available at this moment - we are working to re-enable it soon")
168+
169+
if resp.InstanceID != "" {
170+
_, err := apiClient.DetachVolume(d.Id())
171+
if err != nil {
172+
return diag.Errorf("[WARN] an error occurred while trying to detach volume %s, %s", d.Id(), err)
173+
}
174+
175+
time.Sleep(10 * time.Second)
176+
177+
newSize := d.Get("size_gb").(int)
178+
_, err = apiClient.ResizeVolume(d.Id(), newSize)
179+
if err != nil {
180+
return diag.Errorf("[ERR] the volume (%s) size not change %s", d.Id(), err)
197181
}
198-
*/
182+
183+
time.Sleep(2 * time.Second)
184+
185+
attachConfig := civogo.VolumeAttachConfig{
186+
InstanceID: resp.InstanceID,
187+
AttachAtBoot: true,
188+
Region: apiClient.Region,
189+
}
190+
191+
_, err = apiClient.AttachVolume(d.Id(), attachConfig)
192+
if err != nil {
193+
return diag.Errorf("[ERR] an error occurred while trying to attach the volume %s", d.Id())
194+
}
195+
196+
} else {
197+
newSize := d.Get("size_gb").(int)
198+
_, err = apiClient.ResizeVolume(d.Id(), newSize)
199+
if err != nil {
200+
return diag.Errorf("[ERR] the volume (%s) size not change %s", d.Id(), err)
201+
}
202+
}
199203
}
200204

201205
if d.HasChange("network_id") {

0 commit comments

Comments
 (0)