diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index 452bf0951..055202c46 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -86,10 +86,10 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { } } - m, _ := regexp.MatchString("(stop|terminate)", c.InstanceInitiatedShutdownBehavior) + var reShutdownBehavior = regexp.MustCompile("(stop|terminate)") if c.InstanceInitiatedShutdownBehavior == "" { c.InstanceInitiatedShutdownBehavior = "stop" - } else if !m { + } else if !reShutdownBehavior.MatchString(c.InstanceInitiatedShutdownBehavior) { errs = append(errs, fmt.Errorf("shutdown_behaviour only accepts 'stop' or 'terminate' values.")) }