From be02b3f61387bb49ce8954ed2cd333f2ffaa97a5 Mon Sep 17 00:00:00 2001 From: DanHam Date: Sat, 12 May 2018 16:20:01 +0100 Subject: [PATCH] Validate template settings when T2 Unlimited has been enabled * T2 Unlimited cannot be used with anything other than T2 instance types * T2 Unlimited cannot be used with Spot Instances --- builder/amazon/common/run_config.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index 5922060c2..cd40c9dc4 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -6,6 +6,7 @@ import ( "net" "os" "regexp" + "strings" "time" "github.com/hashicorp/packer/common/uuid" @@ -142,6 +143,18 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { errs = append(errs, fmt.Errorf("shutdown_behavior only accepts 'stop' or 'terminate' values.")) } + if c.EnableT2Unlimited { + if c.SpotPrice != "" { + errs = append(errs, fmt.Errorf("Error: T2 Unlimited cannot be used in conjuction with Spot Instances")) + } + firstDotIndex := strings.Index(c.InstanceType, ".") + if firstDotIndex == -1 { + errs = append(errs, fmt.Errorf("Error determining main Instance Type from: %s", c.InstanceType)) + } else if c.InstanceType[0:firstDotIndex] != "t2" { + errs = append(errs, fmt.Errorf("Error: T2 Unlimited enabled with a non-T2 Instance Type: %s", c.InstanceType)) + } + } + return errs }