diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index cd40c9dc4..99cdc86ae 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -112,6 +112,13 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { } } + if c.SpotPriceAutoProduct != "" { + if c.SpotPrice != "auto" { + errs = append(errs, errors.New( + "spot_price should be set to auto when spot_price_auto_product is specified")) + } + } + if c.UserData != "" && c.UserDataFile != "" { errs = append(errs, fmt.Errorf("Only one of user_data or user_data_file can be specified.")) } else if c.UserDataFile != "" { diff --git a/builder/amazon/common/run_config_test.go b/builder/amazon/common/run_config_test.go index 212f70c02..ae9a547c0 100644 --- a/builder/amazon/common/run_config_test.go +++ b/builder/amazon/common/run_config_test.go @@ -118,13 +118,19 @@ func TestRunConfigPrepare_SpotAuto(t *testing.T) { c := testConfig() c.SpotPrice = "auto" if err := c.Prepare(nil); len(err) != 1 { - t.Fatalf("err: %s", err) + t.Fatalf("spot_price_auto_product should be set when spot_price is set to auto") } + // Good - SpotPrice and SpotPriceAutoProduct are correctly set c.SpotPriceAutoProduct = "foo" if err := c.Prepare(nil); len(err) != 0 { t.Fatalf("err: %s", err) } + + c.SpotPrice = "" + if err := c.Prepare(nil); len(err) != 1 { + t.Fatalf("spot_price should be set to auto when spot_price_auto_product is set") + } } func TestRunConfigPrepare_SSHPort(t *testing.T) {