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
This commit is contained in:
DanHam 2018-05-12 16:20:01 +01:00
parent 482629ae90
commit be02b3f613
No known key found for this signature in database
GPG Key ID: 58E79AEDD6AA987E
1 changed files with 13 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"net" "net"
"os" "os"
"regexp" "regexp"
"strings"
"time" "time"
"github.com/hashicorp/packer/common/uuid" "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.")) 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 return errs
} }