diff --git a/builder/amazon/common/step_run_spot_instance.go b/builder/amazon/common/step_run_spot_instance.go index 45d2ebaab..2af83d98f 100644 --- a/builder/amazon/common/step_run_spot_instance.go +++ b/builder/amazon/common/step_run_spot_instance.go @@ -302,8 +302,6 @@ func (s *StepRunSpotInstance) Run(state multistep.StateBag) multistep.StepAction return multistep.ActionHalt } - return multistep.ActionContinue - } if s.Debug { diff --git a/builder/amazon/common/step_tag_ebs_volumes.go b/builder/amazon/common/step_tag_ebs_volumes.go deleted file mode 100644 index cf4c69a17..000000000 --- a/builder/amazon/common/step_tag_ebs_volumes.go +++ /dev/null @@ -1,65 +0,0 @@ -package common - -import ( - "fmt" - - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/packer/packer" - "github.com/hashicorp/packer/template/interpolate" - "github.com/mitchellh/multistep" -) - -type StepTagEBSVolumes struct { - VolumeRunTags map[string]string - Ctx interpolate.Context -} - -func (s *StepTagEBSVolumes) Run(state multistep.StateBag) multistep.StepAction { - ec2conn := state.Get("ec2").(*ec2.EC2) - instance := state.Get("instance").(*ec2.Instance) - sourceAMI := state.Get("source_image").(*ec2.Image) - ui := state.Get("ui").(packer.Ui) - - if len(s.VolumeRunTags) == 0 { - return multistep.ActionContinue - } - - volumeIds := make([]*string, 0) - for _, v := range instance.BlockDeviceMappings { - if ebs := v.Ebs; ebs != nil { - volumeIds = append(volumeIds, ebs.VolumeId) - } - } - - if len(volumeIds) == 0 { - return multistep.ActionContinue - } - - ui.Say("Adding tags to source EBS Volumes") - tags, err := ConvertToEC2Tags(s.VolumeRunTags, *ec2conn.Config.Region, *sourceAMI.ImageId, s.Ctx) - if err != nil { - err := fmt.Errorf("Error tagging source EBS Volumes on %s: %s", *instance.InstanceId, err) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt - } - - ReportTags(ui, tags) - - _, err = ec2conn.CreateTags(&ec2.CreateTagsInput{ - Resources: volumeIds, - Tags: tags, - }) - if err != nil { - err := fmt.Errorf("Error tagging source EBS Volumes on %s: %s", *instance.InstanceId, err) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt - } - - return multistep.ActionContinue -} - -func (s *StepTagEBSVolumes) Cleanup(state multistep.StateBag) { - // No cleanup... -} diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 53d4d6692..8adf04898 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -111,11 +111,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe var instanceStep multistep.Step if b.config.SpotPrice == "" || b.config.SpotPrice == "0" { - instanceStep = &awscommon.StepRunSpotInstance{ + instanceStep = &awscommon.StepRunSourceInstance{ Debug: b.config.PackerDebug, ExpectedRootDevice: "ebs", - SpotPrice: b.config.SpotPrice, - SpotPriceProduct: b.config.SpotPriceAutoProduct, InstanceType: b.config.InstanceType, UserData: b.config.UserData, UserDataFile: b.config.UserDataFile, @@ -132,9 +130,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior, } } else { - instanceStep = &awscommon.StepRunSourceInstance{ + instanceStep = &awscommon.StepRunSpotInstance{ Debug: b.config.PackerDebug, ExpectedRootDevice: "ebs", + SpotPrice: b.config.SpotPrice, + SpotPriceProduct: b.config.SpotPriceAutoProduct, InstanceType: b.config.InstanceType, UserData: b.config.UserData, UserDataFile: b.config.UserDataFile, diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index 6c0b279e1..bfc572557 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -125,11 +125,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe var instanceStep multistep.Step if b.config.SpotPrice == "" || b.config.SpotPrice == "0" { - instanceStep = &awscommon.StepRunSpotInstance{ + instanceStep = &awscommon.StepRunSourceInstance{ Debug: b.config.PackerDebug, ExpectedRootDevice: "ebs", - SpotPrice: b.config.SpotPrice, - SpotPriceProduct: b.config.SpotPriceAutoProduct, InstanceType: b.config.InstanceType, UserData: b.config.UserData, UserDataFile: b.config.UserDataFile, @@ -146,9 +144,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior, } } else { - instanceStep = &awscommon.StepRunSourceInstance{ + instanceStep = &awscommon.StepRunSpotInstance{ Debug: b.config.PackerDebug, ExpectedRootDevice: "ebs", + SpotPrice: b.config.SpotPrice, + SpotPriceProduct: b.config.SpotPriceAutoProduct, InstanceType: b.config.InstanceType, UserData: b.config.UserData, UserDataFile: b.config.UserDataFile, @@ -192,10 +192,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe VpcId: b.config.VpcId, }, instanceStep, - &awscommon.StepTagEBSVolumes{ - VolumeRunTags: b.config.VolumeRunTags, - Ctx: b.config.ctx, - }, &awscommon.StepGetPassword{ Debug: b.config.PackerDebug, Comm: &b.config.RunConfig.Comm, diff --git a/builder/amazon/ebsvolume/builder.go b/builder/amazon/ebsvolume/builder.go index adbe3efad..603de9ac3 100644 --- a/builder/amazon/ebsvolume/builder.go +++ b/builder/amazon/ebsvolume/builder.go @@ -104,11 +104,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe var instanceStep multistep.Step if b.config.SpotPrice == "" || b.config.SpotPrice == "0" { - instanceStep = &awscommon.StepRunSpotInstance{ + instanceStep = &awscommon.StepRunSourceInstance{ Debug: b.config.PackerDebug, ExpectedRootDevice: "ebs", - SpotPrice: b.config.SpotPrice, - SpotPriceProduct: b.config.SpotPriceAutoProduct, InstanceType: b.config.InstanceType, UserData: b.config.UserData, UserDataFile: b.config.UserDataFile, @@ -123,9 +121,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior, } } else { - instanceStep = &awscommon.StepRunSourceInstance{ + instanceStep = &awscommon.StepRunSpotInstance{ Debug: b.config.PackerDebug, ExpectedRootDevice: "ebs", + SpotPrice: b.config.SpotPrice, + SpotPriceProduct: b.config.SpotPriceAutoProduct, InstanceType: b.config.InstanceType, UserData: b.config.UserData, UserDataFile: b.config.UserDataFile, @@ -163,10 +163,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe VpcId: b.config.VpcId, }, instanceStep, - &stepTagEBSVolumes{ - VolumeMapping: b.config.VolumeMappings, - Ctx: b.config.ctx, - }, &awscommon.StepGetPassword{ Debug: b.config.PackerDebug, Comm: &b.config.RunConfig.Comm, diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index b13d8d8a5..ca75686f6 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -196,11 +196,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe var instanceStep multistep.Step if b.config.SpotPrice == "" || b.config.SpotPrice == "0" { - instanceStep = &awscommon.StepRunSpotInstance{ + instanceStep = &awscommon.StepRunSourceInstance{ Debug: b.config.PackerDebug, ExpectedRootDevice: "ebs", - SpotPrice: b.config.SpotPrice, - SpotPriceProduct: b.config.SpotPriceAutoProduct, InstanceType: b.config.InstanceType, UserData: b.config.UserData, UserDataFile: b.config.UserDataFile, @@ -216,9 +214,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior, } } else { - instanceStep = &awscommon.StepRunSourceInstance{ + instanceStep = &awscommon.StepRunSpotInstance{ Debug: b.config.PackerDebug, ExpectedRootDevice: "ebs", + SpotPrice: b.config.SpotPrice, + SpotPriceProduct: b.config.SpotPriceAutoProduct, InstanceType: b.config.InstanceType, UserData: b.config.UserData, UserDataFile: b.config.UserDataFile,