parent
f84dec91bc
commit
fc30f6cc0a
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue