From 40bd45764c90d26924a4a70103860f1d5e626084 Mon Sep 17 00:00:00 2001 From: Patrick Robinson Date: Mon, 27 Jun 2016 10:28:54 +1000 Subject: [PATCH] Only set InstanceInititatedShutdownBehavior on ebs instances --- .../amazon/common/step_run_source_instance.go | 5 +++- builder/amazon/instance/builder.go | 29 +++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index aac13fb88..c859a0df2 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -148,7 +148,6 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi BlockDeviceMappings: s.BlockDevices.BuildLaunchDevices(), Placement: &ec2.Placement{AvailabilityZone: &s.AvailabilityZone}, EbsOptimized: &s.EbsOptimized, - InstanceInitiatedShutdownBehavior: &s.InstanceInitiatedShutdownBehavior, } if s.SubnetId != "" && s.AssociatePublicIpAddress { @@ -166,6 +165,10 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi runOpts.SecurityGroupIds = securityGroupIds } + if s.ExpectedRootDevice == "ebs" { + runOpts.InstanceInitiatedShutdownBehavior = &s.InstanceInitiatedShutdownBehavior + } + runResp, err := ec2conn.RunInstances(runOpts) if err != nil { err := fmt.Errorf("Error launching source instance: %s", err) diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index 514ff6da7..96b8fa9cc 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -204,21 +204,20 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe VpcId: b.config.VpcId, }, &awscommon.StepRunSourceInstance{ - Debug: b.config.PackerDebug, - SpotPrice: b.config.SpotPrice, - SpotPriceProduct: b.config.SpotPriceAutoProduct, - InstanceType: b.config.InstanceType, - IamInstanceProfile: b.config.IamInstanceProfile, - UserData: b.config.UserData, - UserDataFile: b.config.UserDataFile, - SourceAMI: b.config.SourceAmi, - SubnetId: b.config.SubnetId, - AssociatePublicIpAddress: b.config.AssociatePublicIpAddress, - EbsOptimized: b.config.EbsOptimized, - AvailabilityZone: b.config.AvailabilityZone, - BlockDevices: b.config.BlockDevices, - Tags: b.config.RunTags, - InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior, + Debug: b.config.PackerDebug, + SpotPrice: b.config.SpotPrice, + SpotPriceProduct: b.config.SpotPriceAutoProduct, + InstanceType: b.config.InstanceType, + IamInstanceProfile: b.config.IamInstanceProfile, + UserData: b.config.UserData, + UserDataFile: b.config.UserDataFile, + SourceAMI: b.config.SourceAmi, + SubnetId: b.config.SubnetId, + AssociatePublicIpAddress: b.config.AssociatePublicIpAddress, + EbsOptimized: b.config.EbsOptimized, + AvailabilityZone: b.config.AvailabilityZone, + BlockDevices: b.config.BlockDevices, + Tags: b.config.RunTags, }, &awscommon.StepGetPassword{ Debug: b.config.PackerDebug,