@ -842,62 +842,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
doUpdate := false
resizeReq := compute . ResizeRequest {
ComputeID : computeRec . ID ,
}
forceResize , ok := d . GetOk ( "force_resize" )
if ok {
resizeReq . Force = forceResize . ( bool )
}
warnings := dc . Warnings { }
oldCpu , newCpu := d . GetChange ( "cpu" )
if oldCpu . ( int ) > newCpu . ( int ) && ! forceResize . ( bool ) {
return diag . Errorf ( "Cannot resize compute ID %d: enable 'force_resize' to reduce compute vCPUs" , computeRec . ID )
}
if oldCpu . ( int ) != newCpu . ( int ) {
resizeReq . CPU = uint64 ( newCpu . ( int ) )
doUpdate = true
} else {
resizeReq . CPU = 0
}
if resizeReq . CPU != 0 {
if preferredCPU , ok := d . GetOk ( "preferred_cpu" ) ; ok {
preferredList := preferredCPU . ( [ ] interface { } )
if len ( preferredList ) > 0 {
for _ , v := range preferredList {
cpuNum := v . ( int )
resizeReq . PreferredCPU = append ( resizeReq . PreferredCPU , int64 ( cpuNum ) )
}
}
}
oldPCPU , newPCPU := d . GetChange ( "preferred_cpu" )
if len ( oldPCPU . ( [ ] interface { } ) ) != 0 && len ( newPCPU . ( [ ] interface { } ) ) == 0 {
resizeReq . PreferredCPU = [ ] int64 { - 1 }
}
}
oldRam , newRam := d . GetChange ( "ram" )
if oldRam . ( int ) != newRam . ( int ) {
resizeReq . RAM = uint64 ( newRam . ( int ) )
doUpdate = true
} else {
resizeReq . RAM = 0
}
if doUpdate {
log . Debugf ( "resourceComputeUpdate: changing CPU %d -> %d and/or RAM %d -> %d" ,
oldCpu . ( int ) , newCpu . ( int ) ,
oldRam . ( int ) , newRam . ( int ) )
_ , err := c . CloudAPI ( ) . Compute ( ) . Resize ( ctx , resizeReq )
if err != nil {
return diag . FromErr ( err )
}
}
oldSize , newSize := d . GetChange ( "boot_disk_size" )
if oldSize . ( int ) < newSize . ( int ) {
req := compute . DiskResizeRequest { ComputeID : computeRec . ID }
@ -957,6 +901,74 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
// Note bene: numa_affinity, cpu_pin and hp_backed, cpu, ram are not allowed to be changed for compute in STARTED tech status.
// If STARTED, we need to stop it before update
var isStopRequired bool
if d . HasChanges ( "numa_affinity" , "cpu_pin" , "hp_backed" , "chipset" , "preferred_cpu" ) && d . Get ( "started" ) . ( bool ) {
isStopRequired = true
}
if isStopRequired {
if _ , err := c . CloudAPI ( ) . Compute ( ) . Stop ( ctx , compute . StopRequest { ComputeID : computeRec . ID } ) ; err != nil {
return diag . FromErr ( err )
}
}
doUpdate := false
resizeReq := compute . ResizeRequest {
ComputeID : computeRec . ID ,
}
forceResize , ok := d . GetOk ( "force_resize" )
if ok {
resizeReq . Force = forceResize . ( bool )
}
warnings := dc . Warnings { }
oldCpu , newCpu := d . GetChange ( "cpu" )
if oldCpu . ( int ) > newCpu . ( int ) && ! forceResize . ( bool ) {
return diag . Errorf ( "Cannot resize compute ID %d: enable 'force_resize' to reduce compute vCPUs" , computeRec . ID )
}
if oldCpu . ( int ) != newCpu . ( int ) {
resizeReq . CPU = uint64 ( newCpu . ( int ) )
doUpdate = true
} else {
resizeReq . CPU = 0
}
if resizeReq . CPU != 0 {
if preferredCPU , ok := d . GetOk ( "preferred_cpu" ) ; ok {
preferredList := preferredCPU . ( [ ] interface { } )
if len ( preferredList ) > 0 {
for _ , v := range preferredList {
cpuNum := v . ( int )
resizeReq . PreferredCPU = append ( resizeReq . PreferredCPU , int64 ( cpuNum ) )
}
}
}
oldPCPU , newPCPU := d . GetChange ( "preferred_cpu" )
if len ( oldPCPU . ( [ ] interface { } ) ) != 0 && len ( newPCPU . ( [ ] interface { } ) ) == 0 {
resizeReq . PreferredCPU = [ ] int64 { - 1 }
}
}
oldRam , newRam := d . GetChange ( "ram" )
if oldRam . ( int ) != newRam . ( int ) {
resizeReq . RAM = uint64 ( newRam . ( int ) )
doUpdate = true
} else {
resizeReq . RAM = 0
}
if doUpdate {
log . Debugf ( "resourceComputeUpdate: changing CPU %d -> %d and/or RAM %d -> %d" ,
oldCpu . ( int ) , newCpu . ( int ) ,
oldRam . ( int ) , newRam . ( int ) )
_ , err := c . CloudAPI ( ) . Compute ( ) . Resize ( ctx , resizeReq )
if err != nil {
return diag . FromErr ( err )
}
}
if d . HasChanges ( "description" ,
"name" ,
"numa_affinity" ,
@ -1020,28 +1032,17 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
req . NetworkInterfaceNaming = d . Get ( "network_interface_naming" ) . ( string )
}
// Note bene: numa_affinity, cpu_pin and hp_backed are not allowed to be changed for compute in STARTED tech status.
// If STARTED, we need to stop it before update
var isStopRequired bool
if d . HasChanges ( "numa_affinity" , "cpu_pin" , "hp_backed" , "chipset" , "preferred_cpu" ) && d . Get ( "started" ) . ( bool ) {
isStopRequired = true
}
if isStopRequired {
if _ , err := c . CloudAPI ( ) . Compute ( ) . Stop ( ctx , compute . StopRequest { ComputeID : computeRec . ID } ) ; err != nil {
return diag . FromErr ( err )
}
}
// perform update
if _ , err := c . CloudAPI ( ) . Compute ( ) . Update ( ctx , req ) ; err != nil {
return diag . FromErr ( err )
}
// If used to be STARTED, we need to start it after update
if isStopRequired {
if _ , err := c . CloudAPI ( ) . Compute ( ) . Start ( ctx , compute . StartRequest { ComputeID : computeRec . ID } ) ; err != nil {
return diag . FromErr ( err )
}
}
// If used to be STARTED, we need to start it after update
if isStopRequired {
if _ , err := c . CloudAPI ( ) . Compute ( ) . Start ( ctx , compute . StartRequest { ComputeID : computeRec . ID } ) ; err != nil {
return diag . FromErr ( err )
}
}
@ -1206,24 +1207,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d . HasChange ( "started" ) {
if d . Get ( "started" ) . ( bool ) {
req := compute . StartRequest {
ComputeID : computeRec . ID ,
}
if _ , err := c . CloudAPI ( ) . Compute ( ) . Start ( ctx , req ) ; err != nil {
return diag . FromErr ( err )
}
} else {
req := compute . StopRequest {
ComputeID : computeRec . ID ,
}
if _ , err := c . CloudAPI ( ) . Compute ( ) . Stop ( ctx , req ) ; err != nil {
return diag . FromErr ( err )
}
}
}
if d . HasChange ( "affinity_label" ) {
affinityLabel := d . Get ( "affinity_label" ) . ( string )
if affinityLabel == "" {