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"`
|
SourceAmi string `mapstructure:"source_ami"`
|
||||||
SpotPrice string `mapstructure:"spot_price"`
|
SpotPrice string `mapstructure:"spot_price"`
|
||||||
SpotPriceAutoProduct string `mapstructure:"spot_price_auto_product"`
|
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"`
|
SecurityGroupIds []string `mapstructure:"security_group_ids"`
|
||||||
SubnetId string `mapstructure:"subnet_id"`
|
SubnetId string `mapstructure:"subnet_id"`
|
||||||
TemporaryKeyPairName string `mapstructure:"temporary_key_pair_name"`
|
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),
|
b.config.RunConfig.Comm.SSHUsername),
|
||||||
},
|
},
|
||||||
&common.StepProvision{},
|
&common.StepProvision{},
|
||||||
&stepStopInstance{SpotPrice: b.config.SpotPrice},
|
&stepStopInstance{
|
||||||
|
SpotPrice: b.config.SpotPrice,
|
||||||
|
DisableStopInstance: b.config.DisableStopInstance,
|
||||||
|
},
|
||||||
// TODO(mitchellh): verify works with spots
|
// TODO(mitchellh): verify works with spots
|
||||||
&stepModifyInstance{},
|
&stepModifyInstance{},
|
||||||
&awscommon.StepDeregisterAMI{
|
&awscommon.StepDeregisterAMI{
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
type stepStopInstance struct {
|
type stepStopInstance struct {
|
||||||
SpotPrice string
|
SpotPrice string
|
||||||
|
DisableStopInstance bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepStopInstance) Run(state multistep.StateBag) multistep.StepAction {
|
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
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the instance so we can create an AMI from it
|
var err error
|
||||||
ui.Say("Stopping the source instance...")
|
|
||||||
_, err := ec2conn.StopInstances(&ec2.StopInstancesInput{
|
if s.DisableStopInstance == false {
|
||||||
InstanceIds: []*string{instance.InstanceId},
|
// Stop the instance so we can create an AMI from it
|
||||||
})
|
ui.Say("Stopping the source instance...")
|
||||||
if err != nil {
|
_, err = ec2conn.StopInstances(&ec2.StopInstancesInput{
|
||||||
err := fmt.Errorf("Error stopping instance: %s", err)
|
InstanceIds: []*string{instance.InstanceId},
|
||||||
state.Put("error", err)
|
})
|
||||||
ui.Error(err.Error())
|
if err != nil {
|
||||||
return multistep.ActionHalt
|
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
|
// Wait for the instance to actual stop
|
||||||
ui.Say("Waiting for the instance to stop...")
|
ui.Say("Waiting for the instance to stop...")
|
||||||
|
|
Loading…
Reference in New Issue