From fc30f6cc0af5e52b8d0c42c88e37fcbd220821f1 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Thu, 19 Jan 2017 12:00:41 -0800 Subject: [PATCH] log tag creation. closes #4427 --- builder/amazon/common/step_create_tags.go | 19 +++++++++++-------- .../amazon/common/step_run_source_instance.go | 2 +- builder/amazon/ebs/step_tag_ebs_volumes.go | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/builder/amazon/common/step_create_tags.go b/builder/amazon/common/step_create_tags.go index 4de8e50c3..b3a811bad 100644 --- a/builder/amazon/common/step_create_tags.go +++ b/builder/amazon/common/step_create_tags.go @@ -2,6 +2,7 @@ package common import ( "fmt" + "log" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" @@ -30,11 +31,6 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction { for region, ami := range amis { ui.Say(fmt.Sprintf("Adding tags to AMI (%s)...", ami)) - // Convert tags to ec2.Tag format - amiTags := ConvertToEC2Tags(s.Tags) - ui.Say(fmt.Sprintf("Snapshot tags:")) - snapshotTags := ConvertToEC2Tags(s.SnapshotTags) - // Declare list of resources to tag awsConfig := aws.Config{ Credentials: ec2conn.Config.Credentials, @@ -81,6 +77,12 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction { } } + // Convert tags to ec2.Tag format + ui.Say("Creating AMI tags") + amiTags := ConvertToEC2Tags(s.Tags) + ui.Say("Creating snapshot tags") + snapshotTags := ConvertToEC2Tags(s.SnapshotTags) + // Retry creating tags for about 2.5 minutes err = retry.Retry(0.2, 30, 11, func() (bool, error) { // Tag images and snapshots @@ -129,12 +131,13 @@ func (s *StepCreateTags) Cleanup(state multistep.StateBag) { } func ConvertToEC2Tags(tags map[string]string) []*ec2.Tag { - var amiTags []*ec2.Tag + var ec2tags []*ec2.Tag for key, value := range tags { - amiTags = append(amiTags, &ec2.Tag{ + log.Printf("[DEBUG] Creating tag %s=%s", key, value) + ec2tags = append(ec2tags, &ec2.Tag{ Key: aws.String(key), Value: aws.String(value), }) } - return amiTags + return ec2tags } diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index a26144270..3b61a2485 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -271,7 +271,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi instance := latestInstance.(*ec2.Instance) - ui.Say(fmt.Sprintf("Adding tags to source instance:")) + ui.Say("Adding tags to source instance") if _, exists := s.Tags["Name"]; !exists { s.Tags["Name"] = "Packer Builder" } diff --git a/builder/amazon/ebs/step_tag_ebs_volumes.go b/builder/amazon/ebs/step_tag_ebs_volumes.go index ee5a26bb2..bf7355c8d 100644 --- a/builder/amazon/ebs/step_tag_ebs_volumes.go +++ b/builder/amazon/ebs/step_tag_ebs_volumes.go @@ -33,7 +33,7 @@ func (s *stepTagEBSVolumes) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionContinue } - ui.Say(fmt.Sprintf("Adding tags to source EBS Volumes:")) + ui.Say("Adding tags to source EBS Volumes") tags := common.ConvertToEC2Tags(s.VolumeRunTags) _, err := ec2conn.CreateTags(&ec2.CreateTagsInput{