Add shutdown_behaviour option

This means an instance will terminate upon shutdown.
This commit is contained in:
Patrick Robinson 2016-05-20 19:54:45 +10:00 committed by Chris Bednarski
parent 55138b700e
commit a9f914ea97
4 changed files with 67 additions and 54 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"time"
"regexp"
"github.com/mitchellh/packer/common/uuid"
"github.com/mitchellh/packer/helper/communicator"
@ -32,6 +33,7 @@ type RunConfig struct {
UserDataFile string `mapstructure:"user_data_file"`
WindowsPasswordTimeout time.Duration `mapstructure:"windows_password_timeout"`
VpcId string `mapstructure:"vpc_id"`
InstanceInitiatedShutdownBehavior string `mapstructure:"shutdown_behaviour"`
// Communicator settings
Comm communicator.Config `mapstructure:",squash"`
@ -84,5 +86,12 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
}
}
m, _ := regexp.MatchString("(stop|terminate)", c.InstanceInitiatedShutdownBehavior)
if c.InstanceInitiatedShutdownBehavior == "" {
c.InstanceInitiatedShutdownBehavior = "stop"
} else if !m {
errs = append(errs, fmt.Errorf("shutdown_behaviour only accepts 'stop' or 'terminate' values."))
}
return errs
}

View File

@ -31,6 +31,7 @@ type StepRunSourceInstance struct {
Tags map[string]string
UserData string
UserDataFile string
InstanceInitiatedShutdownBehavior string
instanceId string
spotRequest *ec2.SpotInstanceRequest
@ -147,6 +148,7 @@ 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 {

View File

@ -132,6 +132,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
AvailabilityZone: b.config.AvailabilityZone,
BlockDevices: b.config.BlockDevices,
Tags: b.config.RunTags,
InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior,
},
&stepTagEBSVolumes{
VolumeRunTags: b.config.VolumeRunTags,

View File

@ -218,6 +218,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
AvailabilityZone: b.config.AvailabilityZone,
BlockDevices: b.config.BlockDevices,
Tags: b.config.RunTags,
InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior,
},
&awscommon.StepGetPassword{
Debug: b.config.PackerDebug,