Add option to tell packer not to stop the instance
It is sometimes desirable to sysprep a windows machine before creating an EC2 image. The AWS-approved way to do this is to run ec2configservice.exe -sysprep and let ec2configservice shut down the instance. This change adds an option to disable the stop instance call issued by packer so that the user can control when the machine is stopped.
This commit is contained in:
parent
427cbef249
commit
72a7123a0b
|
@ -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"`
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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...")
|
||||
|
|
Loading…
Reference in New Issue