Skip to content

Commit 807b998

Browse files
committed
move spot_allocation_strategy check to prepare step
1 parent 643bd38 commit 807b998

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

builder/common/run_config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import (
1111
"net"
1212
"os"
1313
"regexp"
14+
"slices"
1415
"strings"
1516
"time"
1617

18+
"github.com/aws/aws-sdk-go/service/ec2"
1719
"github.com/hashicorp/packer-plugin-sdk/communicator"
1820
"github.com/hashicorp/packer-plugin-sdk/template/config"
1921
confighelper "github.com/hashicorp/packer-plugin-sdk/template/config"
@@ -849,6 +851,13 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
849851
}
850852
}
851853

854+
if c.SpotAllocationStrategy != "" {
855+
if !slices.Contains(ec2.SpotAllocationStrategy_Values(), c.SpotAllocationStrategy) {
856+
errs = append(errs, fmt.Errorf(
857+
"Unknown spot_allocation_strategy: %s", c.SpotAllocationStrategy))
858+
}
859+
}
860+
852861
if c.UserData != "" && c.UserDataFile != "" {
853862
errs = append(errs, fmt.Errorf("Only one of user_data or user_data_file can be specified."))
854863
} else if c.UserDataFile != "" {

builder/common/step_run_spot_instance.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"io/ioutil"
1111
"log"
12-
"slices"
1312
"strings"
1413
"time"
1514

@@ -385,7 +384,7 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
385384
Type: aws.String("instant"),
386385
}
387386

388-
if slices.Contains(ec2.SpotAllocationStrategy_Values(), s.SpotAllocationStrategy) {
387+
if s.SpotAllocationStrategy != "" {
389388
createFleetInput.SpotOptions = &ec2.SpotOptionsRequest{
390389
AllocationStrategy: aws.String(s.SpotAllocationStrategy),
391390
}

0 commit comments

Comments
 (0)