scaleway: add support for timeout in shutdown step
This commit is contained in:
parent
08fd0a7e33
commit
557bffc94a
|
@ -98,6 +98,8 @@ type Config struct {
|
||||||
// available.
|
// available.
|
||||||
// Deprecated, use Zone instead
|
// Deprecated, use Zone instead
|
||||||
Region string `mapstructure:"region" required:"false"`
|
Region string `mapstructure:"region" required:"false"`
|
||||||
|
|
||||||
|
Timeout string `mapstructure:"timeout" required:"false"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package scaleway
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
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
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceResp, err := instanceAPI.WaitForServer(&instance.WaitForServerRequest{
|
waitRequest := &instance.WaitForServerRequest{
|
||||||
ServerID: serverID,
|
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 {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error shutting down server: %s", err)
|
err := fmt.Errorf("Error shutting down server: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
Loading…
Reference in New Issue