Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder/amazon: numbers are valid in ami name #4768

Merged
merged 1 commit into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions builder/amazon/common/ami_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions builder/amazon/common/ami_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}

}