amazon-ebssurrogate clean up volumes

This commit is contained in:
Anshul Sharma 2018-07-26 09:30:51 +03:00
parent 5fb6f69ad7
commit c1edcd3774
No known key found for this signature in database
GPG Key ID: 184D0287671243D1
3 changed files with 9 additions and 7 deletions

View File

@ -1,4 +1,4 @@
package ebs package common
import ( import (
"context" "context"
@ -6,7 +6,6 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/packer/builder/amazon/common"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
) )
@ -14,16 +13,16 @@ import (
// stepCleanupVolumes cleans up any orphaned volumes that were not designated to // stepCleanupVolumes cleans up any orphaned volumes that were not designated to
// remain after termination of the instance. These volumes are typically ones // remain after termination of the instance. These volumes are typically ones
// that are marked as "delete on terminate:false" in the source_ami of a build. // that are marked as "delete on terminate:false" in the source_ami of a build.
type stepCleanupVolumes struct { type StepCleanupVolumes struct {
BlockDevices common.BlockDevices BlockDevices BlockDevices
} }
func (s *stepCleanupVolumes) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCleanupVolumes) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
// stepCleanupVolumes is for Cleanup only // stepCleanupVolumes is for Cleanup only
return multistep.ActionContinue return multistep.ActionContinue
} }
func (s *stepCleanupVolumes) Cleanup(state multistep.StateBag) { func (s *StepCleanupVolumes) Cleanup(state multistep.StateBag) {
ec2conn := state.Get("ec2").(*ec2.EC2) ec2conn := state.Get("ec2").(*ec2.EC2)
instanceRaw := state.Get("instance") instanceRaw := state.Get("instance")
var instance *ec2.Instance var instance *ec2.Instance

View File

@ -191,7 +191,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
VpcId: b.config.VpcId, VpcId: b.config.VpcId,
TemporarySGSourceCidr: b.config.TemporarySGSourceCidr, TemporarySGSourceCidr: b.config.TemporarySGSourceCidr,
}, },
&stepCleanupVolumes{ &awscommon.StepCleanupVolumes{
BlockDevices: b.config.BlockDevices, BlockDevices: b.config.BlockDevices,
}, },
instanceStep, instanceStep,

View File

@ -208,6 +208,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
VpcId: b.config.VpcId, VpcId: b.config.VpcId,
TemporarySGSourceCidr: b.config.TemporarySGSourceCidr, TemporarySGSourceCidr: b.config.TemporarySGSourceCidr,
}, },
&awscommon.StepCleanupVolumes{
BlockDevices: b.config.BlockDevices,
},
instanceStep, instanceStep,
&awscommon.StepGetPassword{ &awscommon.StepGetPassword{
Debug: b.config.PackerDebug, Debug: b.config.PackerDebug,