Adds support for adding tags to the AMI

This commit is contained in:
James Massara 2013-08-01 16:31:07 -07:00
parent 5b7d8fbc74
commit 096a64ad92
3 changed files with 21 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package common
import (
"errors"
"fmt"
"github.com/mitchellh/goamz/ec2"
"time"
)
@ -18,6 +19,7 @@ type RunConfig struct {
SecurityGroupId string `mapstructure:"security_group_id"`
SubnetId string `mapstructure:"subnet_id"`
VpcId string `mapstructure:"vpc_id"`
Tags []ec2.Tag
// Unexported fields that are calculated from others
sshTimeout time.Duration

View File

@ -107,7 +107,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
&common.StepProvision{},
&stepStopInstance{},
&stepCreateAMI{},
&stepCreateAMI{
Tags: b.config.Tags,
},
}
// Run!

View File

@ -12,7 +12,9 @@ import (
"time"
)
type stepCreateAMI struct{}
type stepCreateAMI struct {
Tags []ec2.Tag
}
type amiNameData struct {
CreateTime string
@ -64,6 +66,19 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) multistep.StepAction {
return multistep.ActionHalt
}
// Add tags to AMI
if s.Tags != nil {
ui.Say(fmt.Sprintf("Add tags to AMI (%s)...", createResp.ImageId))
amiId := []string{createResp.ImageId}
_, err := ec2conn.CreateTags(amiId, s.Tags)
if err != nil {
err := fmt.Errorf("Error adding tags to AMI (%s): %s", createResp.ImageId, err)
state["error"] = err
ui.Error(err.Error())
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}