From 74c8c585f52fba7a2adb7f38a4ff35f785ae499c Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Thu, 23 Mar 2017 16:12:59 -0700 Subject: [PATCH] builder/amazon: report tag creation --- builder/amazon/common/step_create_tags.go | 11 +++++++++-- builder/amazon/common/step_run_source_instance.go | 2 ++ builder/amazon/common/step_tag_ebs_volumes.go | 2 ++ builder/amazon/ebsvolume/step_tag_ebs_volumes.go | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/builder/amazon/common/step_create_tags.go b/builder/amazon/common/step_create_tags.go index 195c577f9..42c221dbb 100644 --- a/builder/amazon/common/step_create_tags.go +++ b/builder/amazon/common/step_create_tags.go @@ -2,7 +2,6 @@ package common import ( "fmt" - "log" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" @@ -94,6 +93,7 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction { ui.Error(err.Error()) return multistep.ActionHalt } + ReportTags(ui, amiTags) ui.Say("Creating snapshot tags") snapshotTags, err := ConvertToEC2Tags(s.SnapshotTags, *ec2conn.Config.Region, sourceAMI, s.Ctx) @@ -102,6 +102,7 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction { ui.Error(err.Error()) return multistep.ActionHalt } + ReportTags(ui, snapshotTags) // Retry creating tags for about 2.5 minutes err = retry.Retry(0.2, 30, 11, func() (bool, error) { @@ -150,6 +151,13 @@ func (s *StepCreateTags) Cleanup(state multistep.StateBag) { // No cleanup... } +func ReportTags(ui packer.Ui, tags []*ec2.Tag) { + for _, tag := range tags { + ui.Message(fmt.Sprintf("Adding tag: \"%s\": \"%s\"", + aws.StringValue(tag.Key), aws.StringValue(tag.Value))) + } +} + func ConvertToEC2Tags(tags map[string]string, region, sourceAmiId string, ctx interpolate.Context) ([]*ec2.Tag, error) { var ec2Tags []*ec2.Tag for key, value := range tags { @@ -163,7 +171,6 @@ func ConvertToEC2Tags(tags map[string]string, region, sourceAmiId string, ctx in return ec2Tags, fmt.Errorf("Error processing tag: %s:%s - %s", key, value, err) } - log.Printf("Adding tag: \"%s\": \"%s\"", key, interpolatedValue) ec2Tags = append(ec2Tags, &ec2.Tag{ Key: aws.String(key), Value: aws.String(interpolatedValue), diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index 040cb351c..8ac837875 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -289,6 +289,8 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi return multistep.ActionHalt } + ReportTags(ui, ec2Tags) + _, err = ec2conn.CreateTags(&ec2.CreateTagsInput{ Tags: ec2Tags, Resources: []*string{instance.InstanceId}, diff --git a/builder/amazon/common/step_tag_ebs_volumes.go b/builder/amazon/common/step_tag_ebs_volumes.go index 9a912600a..4d9c5d66a 100644 --- a/builder/amazon/common/step_tag_ebs_volumes.go +++ b/builder/amazon/common/step_tag_ebs_volumes.go @@ -44,6 +44,8 @@ func (s *StepTagEBSVolumes) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } + ReportTags(ui, tags) + _, err = ec2conn.CreateTags(&ec2.CreateTagsInput{ Resources: volumeIds, Tags: tags, diff --git a/builder/amazon/ebsvolume/step_tag_ebs_volumes.go b/builder/amazon/ebsvolume/step_tag_ebs_volumes.go index ba6c9ccfa..48d373ba1 100644 --- a/builder/amazon/ebsvolume/step_tag_ebs_volumes.go +++ b/builder/amazon/ebsvolume/step_tag_ebs_volumes.go @@ -50,6 +50,7 @@ func (s *stepTagEBSVolumes) Run(state multistep.StateBag) multistep.StepAction { ui.Error(err.Error()) return multistep.ActionHalt } + awscommon.ReportTags(ui, tags) for _, v := range instance.BlockDeviceMappings { if *v.DeviceName == mapping.DeviceName {