|
|
|
|
@ -6,11 +6,13 @@ import (
|
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
|
|
|
|
multierror "github.com/hashicorp/go-multierror"
|
|
|
|
|
awscommon "github.com/hashicorp/packer/builder/amazon/common"
|
|
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// StepSnapshotVolumes creates snapshots of the created volumes.
|
|
|
|
|
@ -23,6 +25,8 @@ type StepSnapshotVolumes struct {
|
|
|
|
|
snapshotIds map[string]string
|
|
|
|
|
snapshotMutex sync.Mutex
|
|
|
|
|
SnapshotOmitMap map[string]bool
|
|
|
|
|
SnapshotTags map[string]string
|
|
|
|
|
Ctx interpolate.Context
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *StepSnapshotVolumes) snapshotVolume(ctx context.Context, deviceName string, state multistep.StateBag) error {
|
|
|
|
|
@ -40,12 +44,34 @@ func (s *StepSnapshotVolumes) snapshotVolume(ctx context.Context, deviceName str
|
|
|
|
|
return fmt.Errorf("Volume ID for device %s not found", deviceName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.Say("Creating snapshot tags")
|
|
|
|
|
snapshotTags, err := awscommon.TagMap(s.SnapshotTags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
|
|
|
|
if err != nil {
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
snapshotTags.Report(ui)
|
|
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Creating snapshot of EBS Volume %s...", volumeId))
|
|
|
|
|
description := fmt.Sprintf("Packer: %s", time.Now().String())
|
|
|
|
|
|
|
|
|
|
// Collect tags for tagging on resource creation
|
|
|
|
|
var tagSpecs []*ec2.TagSpecification
|
|
|
|
|
|
|
|
|
|
if len(snapshotTags) > 0 {
|
|
|
|
|
snapTags := &ec2.TagSpecification{
|
|
|
|
|
ResourceType: aws.String("snapshot"),
|
|
|
|
|
Tags: snapshotTags,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tagSpecs = append(tagSpecs, snapTags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createSnapResp, err := ec2conn.CreateSnapshot(&ec2.CreateSnapshotInput{
|
|
|
|
|
VolumeId: &volumeId,
|
|
|
|
|
Description: &description,
|
|
|
|
|
VolumeId: &volumeId,
|
|
|
|
|
Description: &description,
|
|
|
|
|
TagSpecifications: tagSpecs,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
|