scaleway: add support for timeout in shutdown step

This commit is contained in:
Rémy Léone 2021-01-20 21:41:39 +01:00
parent 08fd0a7e33
commit 557bffc94a
2 changed files with 18 additions and 2 deletions

View File

@ -98,6 +98,8 @@ type Config struct {
// available.
// Deprecated, use Zone instead
Region string `mapstructure:"region" required:"false"`
Timeout string `mapstructure:"timeout" required:"false"`
}
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {

View File

@ -3,6 +3,7 @@ package scaleway
import (
"context"
"fmt"
"time"
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
@ -30,9 +31,22 @@ func (s *stepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
return multistep.ActionHalt
}
instanceResp, err := instanceAPI.WaitForServer(&instance.WaitForServerRequest{
waitRequest := &instance.WaitForServerRequest{
ServerID: serverID,
})
}
timeout := state.Get("timeout").(string)
duration, err := time.ParseDuration(timeout)
if err != nil {
err := fmt.Errorf("error: %s could not parse string %s as a duration", err, timeout)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
if timeout != "" {
waitRequest.Timeout = scw.TimeDurationPtr(duration)
}
instanceResp, err := instanceAPI.WaitForServer(waitRequest)
if err != nil {
err := fmt.Errorf("Error shutting down server: %s", err)
state.Put("error", err)