|
|
|
|
@ -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),
|
|
|
|
|
|