diff --git a/builder/scaleway/config.go b/builder/scaleway/config.go index 3f5277c24..878f5be1d 100644 --- a/builder/scaleway/config.go +++ b/builder/scaleway/config.go @@ -74,8 +74,10 @@ type Config struct { RemoveVolume bool `mapstructure:"remove_volume"` - UserAgent string `mapstructure-to-hcl2:",skip"` - ctx interpolate.Context + // Shutdown timeout. Default to 5m + ShutdownTimeout string `mapstructure:"shutdown_timeout" required:"false"` + UserAgent string `mapstructure-to-hcl2:",skip"` + ctx interpolate.Context // Deprecated configs @@ -255,6 +257,10 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) { errs, errors.New("image is required")) } + if c.ShutdownTimeout == "" { + c.ShutdownTimeout = "5m" + } + if errs != nil && len(errs.Errors) > 0 { return warnings, errs } diff --git a/builder/scaleway/config.hcl2spec.go b/builder/scaleway/config.hcl2spec.go index 32a04f1eb..720e02dae 100644 --- a/builder/scaleway/config.hcl2spec.go +++ b/builder/scaleway/config.hcl2spec.go @@ -80,6 +80,7 @@ type FlatConfig struct { Bootscript *string `mapstructure:"bootscript" required:"false" cty:"bootscript" hcl:"bootscript"` BootType *string `mapstructure:"boottype" required:"false" cty:"boottype" hcl:"boottype"` RemoveVolume *bool `mapstructure:"remove_volume" cty:"remove_volume" hcl:"remove_volume"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout" hcl:"shutdown_timeout"` Token *string `mapstructure:"api_token" required:"false" cty:"api_token" hcl:"api_token"` Organization *string `mapstructure:"organization_id" required:"false" cty:"organization_id" hcl:"organization_id"` Region *string `mapstructure:"region" required:"false" cty:"region" hcl:"region"` @@ -167,6 +168,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "bootscript": &hcldec.AttrSpec{Name: "bootscript", Type: cty.String, Required: false}, "boottype": &hcldec.AttrSpec{Name: "boottype", Type: cty.String, Required: false}, "remove_volume": &hcldec.AttrSpec{Name: "remove_volume", Type: cty.Bool, Required: false}, + "shutdown_timeout": &hcldec.AttrSpec{Name: "shutdown_timeout", Type: cty.String, Required: false}, "api_token": &hcldec.AttrSpec{Name: "api_token", Type: cty.String, Required: false}, "organization_id": &hcldec.AttrSpec{Name: "organization_id", Type: cty.String, Required: false}, "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, diff --git a/builder/scaleway/step_shutdown.go b/builder/scaleway/step_shutdown.go index 12365a482..164acc607 100644 --- a/builder/scaleway/step_shutdown.go +++ b/builder/scaleway/step_shutdown.go @@ -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,23 @@ 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, - }) + } + c := state.Get("config").(*Config) + timeout := c.ShutdownTimeout + 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) diff --git a/website/content/partials/builder/scaleway/Config-not-required.mdx b/website/content/partials/builder/scaleway/Config-not-required.mdx index ef73b13c1..0e5560984 100644 --- a/website/content/partials/builder/scaleway/Config-not-required.mdx +++ b/website/content/partials/builder/scaleway/Config-not-required.mdx @@ -21,6 +21,8 @@ - `remove_volume` (bool) - Remove Volume +- `shutdown_timeout` (string) - Shutdown timeout. Default to 5m + - `api_token` (string) - The token to use to authenticate with your account. It can also be specified via environment variable SCALEWAY_API_TOKEN. You can see and generate tokens in the "Credentials"