Validation for tag configuration

This commit is contained in:
Harvey Lowndes 2018-06-04 14:18:18 +01:00 committed by Megan Marsh
parent cc7d4e4a95
commit 344e7e8b92
1 changed files with 25 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
@ -183,6 +184,30 @@ func NewConfig(raws ...interface{}) (*Config, error) {
errs, errors.New("'base_image_ocid' must be specified"))
}
// Validate tag lengths. TODO (hlowndes) maximum number of tags allowed.
if c.Tags != nil {
for k, v := range c.Tags {
k = strings.TrimSpace(k)
v = strings.TrimSpace(v)
if len(k) > 100 {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Tag key length too long. Maximum 100 but found %d. Key: %s", len(k), k))
}
if len(k) == 0 {
errs = packer.MultiErrorAppend(
errs, errors.New("Tag key empty in config"))
}
if len(v) > 100 {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Tag value length too long. Maximum 100 but found %d. Key: %s", len(v), k))
}
if len(v) == 0 {
errs = packer.MultiErrorAppend(
errs, errors.New("Tag value empty in config"))
}
}
}
if c.ImageName == "" {
name, err := interpolate.Render("packer-{{timestamp}}", nil)
if err != nil {