Skip to content

Commit eaf3daf

Browse files
committed
fix state
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent 3e00690 commit eaf3daf

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

scaleway/resource_instance_server.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,9 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
485485
return diag.FromErr(err)
486486
}
487487

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
495490

496-
isStopped := instanceResp.Server.State == instance.ServerStateStopped
497491
var warnings diag.Diagnostics
498492

499493
////
@@ -535,7 +529,6 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
535529

536530
for i, volumeID := range raw.([]interface{}) {
537531
// local volumes can only be added when the instance is stopped
538-
// TODO: handle volumes that will be removed from the instance too
539532
if !isStopped {
540533
volumeResp, err := instanceAPI.GetVolume(&instance.GetVolumeRequest{
541534
Zone: zone,
@@ -610,18 +603,22 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
610603
if d.HasChanges("boot_type") {
611604
bootType := instance.BootType(d.Get("boot_type").(string))
612605
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+
}
617612
}
618613

619614
if d.HasChanges("bootscript_id") {
620615
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+
}
625622
}
626623

627624
////
@@ -645,10 +642,12 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
645642
// cloud init script is set in user data
646643
if cloudInit, ok := d.GetOk("cloud_init"); ok {
647644
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+
}
652651
}
653652

654653
err := instanceAPI.SetAllServerUserData(userDataRequests)

0 commit comments

Comments
 (0)