fix panic and don't print each tag we add.

This commit is contained in:
Matthew Hooker 2017-01-18 11:34:36 -08:00
parent d9186dc8cf
commit 800351b7ca
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
4 changed files with 9 additions and 6 deletions

View File

@ -69,6 +69,10 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
c.WindowsPasswordTimeout = 10 * time.Minute
}
if c.RunTags == nil {
c.RunTags = make(map[string]string)
}
// Validation
errs := c.Comm.Prepare(ctx)
if c.SourceAmi == "" && c.SourceAmiFilter.Empty() {

View File

@ -31,9 +31,9 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction {
ui.Say(fmt.Sprintf("Adding tags to AMI (%s)...", ami))
// Convert tags to ec2.Tag format
amiTags := ConvertToEC2Tags(s.Tags, ui)
amiTags := ConvertToEC2Tags(s.Tags)
ui.Say(fmt.Sprintf("Snapshot tags:"))
snapshotTags := ConvertToEC2Tags(s.SnapshotTags, ui)
snapshotTags := ConvertToEC2Tags(s.SnapshotTags)
// Declare list of resources to tag
awsConfig := aws.Config{
@ -128,10 +128,9 @@ func (s *StepCreateTags) Cleanup(state multistep.StateBag) {
// No cleanup...
}
func ConvertToEC2Tags(tags map[string]string, ui packer.Ui) []*ec2.Tag {
func ConvertToEC2Tags(tags map[string]string) []*ec2.Tag {
var amiTags []*ec2.Tag
for key, value := range tags {
ui.Message(fmt.Sprintf("Adding tag: \"%s\": \"%s\"", key, value))
amiTags = append(amiTags, &ec2.Tag{
Key: aws.String(key),
Value: aws.String(value),

View File

@ -295,7 +295,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
if _, exists := s.Tags["Name"]; !exists {
s.Tags["Name"] = "Packer Builder"
}
ec2Tags := ConvertToEC2Tags(s.Tags, ui)
ec2Tags := ConvertToEC2Tags(s.Tags)
_, err = ec2conn.CreateTags(&ec2.CreateTagsInput{
Tags: ec2Tags,

View File

@ -34,7 +34,7 @@ func (s *stepTagEBSVolumes) Run(state multistep.StateBag) multistep.StepAction {
}
ui.Say(fmt.Sprintf("Adding tags to source EBS Volumes:"))
tags := common.ConvertToEC2Tags(s.VolumeRunTags, ui)
tags := common.ConvertToEC2Tags(s.VolumeRunTags)
_, err := ec2conn.CreateTags(&ec2.CreateTagsInput{
Resources: []*string{