log tag creation.

closes #4427
This commit is contained in:
Matthew Hooker 2017-01-19 12:00:41 -08:00
parent f84dec91bc
commit fc30f6cc0a
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
3 changed files with 13 additions and 10 deletions

View File

@ -2,6 +2,7 @@ package common
import ( import (
"fmt" "fmt"
"log"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "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 { for region, ami := range amis {
ui.Say(fmt.Sprintf("Adding tags to AMI (%s)...", ami)) 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 // Declare list of resources to tag
awsConfig := aws.Config{ awsConfig := aws.Config{
Credentials: ec2conn.Config.Credentials, 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 // Retry creating tags for about 2.5 minutes
err = retry.Retry(0.2, 30, 11, func() (bool, error) { err = retry.Retry(0.2, 30, 11, func() (bool, error) {
// Tag images and snapshots // Tag images and snapshots
@ -129,12 +131,13 @@ func (s *StepCreateTags) Cleanup(state multistep.StateBag) {
} }
func ConvertToEC2Tags(tags map[string]string) []*ec2.Tag { func ConvertToEC2Tags(tags map[string]string) []*ec2.Tag {
var amiTags []*ec2.Tag var ec2tags []*ec2.Tag
for key, value := range tags { 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), Key: aws.String(key),
Value: aws.String(value), Value: aws.String(value),
}) })
} }
return amiTags return ec2tags
} }

View File

@ -271,7 +271,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
instance := latestInstance.(*ec2.Instance) 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 { if _, exists := s.Tags["Name"]; !exists {
s.Tags["Name"] = "Packer Builder" s.Tags["Name"] = "Packer Builder"
} }

View File

@ -33,7 +33,7 @@ func (s *stepTagEBSVolumes) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue 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) tags := common.ConvertToEC2Tags(s.VolumeRunTags)
_, err := ec2conn.CreateTags(&ec2.CreateTagsInput{ _, err := ec2conn.CreateTags(&ec2.CreateTagsInput{