Commit 096a64ad authored by James Massara's avatar James Massara

Adds support for adding tags to the AMI

parent 5b7d8fbc
......@@ -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
......
......@@ -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!
......
......@@ -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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment