@@ -485,15 +485,9 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
485
485
return diag .FromErr (err )
486
486
}
487
487
488
- instanceResp , err := instanceAPI .GetServer (& instance.GetServerRequest {
489
- Zone : zone ,
490
- ServerID : ID ,
491
- })
492
- if err != nil {
493
- return diag .FromErr (err )
494
- }
488
+ wantedState := d .Get ("state" ).(string )
489
+ isStopped := wantedState == InstanceServerStateStopped
495
490
496
- isStopped := instanceResp .Server .State == instance .ServerStateStopped
497
491
var warnings diag.Diagnostics
498
492
499
493
////
@@ -535,7 +529,6 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
535
529
536
530
for i , volumeID := range raw .([]interface {}) {
537
531
// local volumes can only be added when the instance is stopped
538
- // TODO: handle volumes that will be removed from the instance too
539
532
if ! isStopped {
540
533
volumeResp , err := instanceAPI .GetVolume (& instance.GetVolumeRequest {
541
534
Zone : zone ,
@@ -610,18 +603,22 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
610
603
if d .HasChanges ("boot_type" ) {
611
604
bootType := instance .BootType (d .Get ("boot_type" ).(string ))
612
605
updateRequest .BootType = & bootType
613
- warnings = append (warnings , diag.Diagnostic {
614
- Severity : diag .Warning ,
615
- Summary : "instance may need to be rebooted to use the new boot type" ,
616
- })
606
+ if ! isStopped {
607
+ warnings = append (warnings , diag.Diagnostic {
608
+ Severity : diag .Warning ,
609
+ Summary : "instance may need to be rebooted to use the new boot type" ,
610
+ })
611
+ }
617
612
}
618
613
619
614
if d .HasChanges ("bootscript_id" ) {
620
615
updateRequest .Bootscript = expandStringPtr (d .Get ("bootscript_id" ).(string ))
621
- warnings = append (warnings , diag.Diagnostic {
622
- Severity : diag .Warning ,
623
- Summary : "instance may need to be rebooted to use the new bootscript" ,
624
- })
616
+ if ! isStopped {
617
+ warnings = append (warnings , diag.Diagnostic {
618
+ Severity : diag .Warning ,
619
+ Summary : "instance may need to be rebooted to use the new bootscript" ,
620
+ })
621
+ }
625
622
}
626
623
627
624
////
@@ -645,10 +642,12 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
645
642
// cloud init script is set in user data
646
643
if cloudInit , ok := d .GetOk ("cloud_init" ); ok {
647
644
userDataRequests .UserData ["cloud-init" ] = bytes .NewBufferString (cloudInit .(string ))
648
- warnings = append (warnings , diag.Diagnostic {
649
- Severity : diag .Warning ,
650
- Summary : "instance may need to be rebooted to use the new cloud init config" ,
651
- })
645
+ if ! isStopped {
646
+ warnings = append (warnings , diag.Diagnostic {
647
+ Severity : diag .Warning ,
648
+ Summary : "instance may need to be rebooted to use the new cloud init config" ,
649
+ })
650
+ }
652
651
}
653
652
654
653
err := instanceAPI .SetAllServerUserData (userDataRequests )
0 commit comments