Moved Tags configuration out of common and into ebs.

This commit is contained in:
James Massara 2013-08-03 20:09:14 -07:00
parent 9d0fdacedf
commit 8bffb4f17b
1 changed files with 29 additions and 1 deletions

View File

@ -27,6 +27,12 @@ type config struct {
// Configuration of the resulting AMI
AMIName string `mapstructure:"ami_name"`
// Tags for the AMI
Tags []map[string]string
// Unexported fields that are calculated from others
ec2Tags []ec2.Tag
}
type Builder struct {
@ -57,6 +63,28 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
}
// Accumulate any errors
if b.config.Tags != nil {
var ec2Tags []ec2.Tag
for _, tag := range b.config.Tags {
if _, ok := tag["key"]; !ok {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Unknown tag configuration, expecting 'key'"))
continue
}
if _, ok := tag["value"]; !ok {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Unknown tag configuration, expecting 'value'"))
continue
}
ec2Tags = append(ec2Tags, ec2.Tag{
Key: tag["key"],
Value: tag["value"],
})
}
b.config.ec2Tags = ec2Tags
}
if errs != nil && len(errs.Errors) > 0 {
return errs
}
@ -108,7 +136,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&common.StepProvision{},
&stepStopInstance{},
&stepCreateAMI{
Tags: b.config.Tags,
Tags: b.config.ec2Tags,
},
}