From da8c4004f0f5b777786799ba909996af626ef3b7 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Wed, 5 Apr 2017 12:39:16 -0700 Subject: [PATCH] builder/amazon: numbers are valid in ami name --- builder/amazon/common/ami_config.go | 7 +++++-- builder/amazon/common/ami_config_test.go | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/builder/amazon/common/ami_config.go b/builder/amazon/common/ami_config.go index 014ca35da1f..a0f299d375d 100644 --- a/builder/amazon/common/ami_config.go +++ b/builder/amazon/common/ami_config.go @@ -73,9 +73,12 @@ func (c *AMIConfig) Prepare(ctx *interpolate.Context) []error { errs = append(errs, fmt.Errorf("AMIName must be between 3 and 128 characters long")) } - amiNameRe := regexp.MustCompile(`^[a-zA-Z().\-/_]+$`) + amiNameRe := regexp.MustCompile(`^[0-9a-zA-Z().\-/_]+$`) if !amiNameRe.MatchString(c.AMIName) { - errs = append(errs, fmt.Errorf("AMIName should only contain letters, numbers, '(', ')', '.', '-', '/' and '_'")) + errs = append(errs, fmt.Errorf("AMIName should only contain letters,"+ + " numbers, '(', ')', '.', '-', '/' and '_'. You can use the "+ + "`clean_ami_name` template filter to automatically clean your ami "+ + "name.")) } if len(errs) > 0 { diff --git a/builder/amazon/common/ami_config_test.go b/builder/amazon/common/ami_config_test.go index 8754062226e..ce85e7fef97 100644 --- a/builder/amazon/common/ami_config_test.go +++ b/builder/amazon/common/ami_config_test.go @@ -102,4 +102,9 @@ func TestAMINameValidation(t *testing.T) { t.Fatal("expected 'foobar' to be a valid ami name") } + c.AMIName = `xyz-base-2017-04-05-1934` + if err := c.Prepare(nil); err != nil { + t.Fatalf("expected `xyz-base-2017-04-05-1934` to pass validation.") + } + }