diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index 307a177ed..f5e237257 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -23,7 +23,8 @@ type RunConfig struct { SourceAmi string `mapstructure:"source_ami"` SpotPrice string `mapstructure:"spot_price"` SpotPriceAutoProduct string `mapstructure:"spot_price_auto_product"` - SecurityGroupId string `mapstructure:"security_group_id"` + DisableStopInstance bool `mapstructure:"disable_stop_instance"` + SecurityGroupId string `mapstructure:"security_group_id"` SecurityGroupIds []string `mapstructure:"security_group_ids"` SubnetId string `mapstructure:"subnet_id"` TemporaryKeyPairName string `mapstructure:"temporary_key_pair_name"` diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index d8e8cea28..ebf496f34 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -150,7 +150,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe b.config.RunConfig.Comm.SSHUsername), }, &common.StepProvision{}, - &stepStopInstance{SpotPrice: b.config.SpotPrice}, + &stepStopInstance{ + SpotPrice: b.config.SpotPrice, + DisableStopInstance: b.config.DisableStopInstance, + }, // TODO(mitchellh): verify works with spots &stepModifyInstance{}, &awscommon.StepDeregisterAMI{ diff --git a/builder/amazon/ebs/step_stop_instance.go b/builder/amazon/ebs/step_stop_instance.go index d6f135368..b536aaf1b 100644 --- a/builder/amazon/ebs/step_stop_instance.go +++ b/builder/amazon/ebs/step_stop_instance.go @@ -11,6 +11,7 @@ import ( type stepStopInstance struct { SpotPrice string + DisableStopInstance bool } func (s *stepStopInstance) Run(state multistep.StateBag) multistep.StepAction { @@ -23,17 +24,21 @@ func (s *stepStopInstance) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionContinue } - // Stop the instance so we can create an AMI from it - ui.Say("Stopping the source instance...") - _, err := ec2conn.StopInstances(&ec2.StopInstancesInput{ - InstanceIds: []*string{instance.InstanceId}, - }) - if err != nil { - err := fmt.Errorf("Error stopping instance: %s", err) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt - } + var err error + + if s.DisableStopInstance == false { + // Stop the instance so we can create an AMI from it + ui.Say("Stopping the source instance...") + _, err = ec2conn.StopInstances(&ec2.StopInstancesInput{ + InstanceIds: []*string{instance.InstanceId}, + }) + if err != nil { + err := fmt.Errorf("Error stopping instance: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } // Wait for the instance to actual stop ui.Say("Waiting for the instance to stop...")