Use SetPartial on changeable resources in update methods for compute and disk

rc-1.0
Sergey Shubin svs1370 4 years ago
parent 44bed84716
commit 5fc08e9dde

@ -178,7 +178,6 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error {
2. Resize (grow) boot disk
3. Update extra disks
4. Update networks
5. Update port forwards
*/
// 1. Resize CPU/RAM
@ -186,6 +185,8 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error {
doUpdate := false
params.Add("computeId", d.Id())
d.Partial(true)
oldCpu, newCpu := d.GetChange("cpu")
if oldCpu.(int) != newCpu.(int) {
params.Add("cpu", fmt.Sprintf("%d", newCpu.(int)))
@ -210,6 +211,8 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
d.SetPartial("cpu")
d.SetPartial("ram")
}
// 2. Resize (grow) Boot disk
@ -224,6 +227,7 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
d.SetPartial("boot_disk_size")
} else if oldSize.(int) > newSize.(int) {
log.Warnf("resourceComputeUpdate: compute ID %d - shrinking boot disk is not allowed", d.Id())
}
@ -232,14 +236,20 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error {
err := controller.utilityComputeExtraDisksConfigure(d, true) // pass do_delta = true to apply changes, if any
if err != nil {
return err
} else {
d.SetPartial("extra_disks")
}
// 4. Calculate and apply changes to network connections
err = controller.utilityComputeNetworksConfigure(d, true) // pass do_delta = true to apply changes, if any
if err != nil {
return err
} else {
d.SetPartial("network")
}
d.Partial(false)
// we may reuse dataSourceComputeRead here as we maintain similarity
// between Compute resource and Compute data source schemas
return dataSourceComputeRead(d, m)

@ -91,6 +91,8 @@ func resourceDiskUpdate(d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceDiskUpdate: called for Disk ID / name % d / %s, Account ID %d",
d.Get("disk_id").(int), d.Get("name").(string), d.Get("account_id").(int))
d.Partial(true)
oldSize, newSize := d.GetChange("size")
if oldSize.(int) > newSize.(int) {
return fmt.Errorf("resourceDiskUpdate: Disk ID %d - shrinking disk size from %d to %d not allowed",
@ -100,6 +102,7 @@ func resourceDiskUpdate(d *schema.ResourceData, m interface{}) error {
if oldSize.(int) == newSize.(int) {
log.Debugf("resourceDiskUpdate: Disk ID %d - no size change required", d.Get("disk_id").(int))
// and there is no need to re-read disk specs either
d.Partial(false)
return nil
}
@ -112,6 +115,9 @@ func resourceDiskUpdate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
d.SetPartial("size")
d.Partial(false)
// we may reuse dataSourceDiskRead here as we maintain similarity
// between Compute resource and Compute data source schemas

Loading…
Cancel
Save