@@ -96,6 +96,12 @@ type Builder struct {
9696 runner multistep.Runner
9797}
9898
99+ func shouldSkipSourceInstanceTerminationWait (config * Config ) bool {
100+ return config .AMISkipCreateImage &&
101+ (len (config .SecurityGroupIds ) > 0 || ! config .SecurityGroupFilter .Empty ()) &&
102+ config .TemporaryIamInstanceProfilePolicyDocument == nil
103+ }
104+
99105func (b * Builder ) ConfigSpec () hcldec.ObjectSpec { return b .config .FlatMapstructure ().HCL2Spec () }
100106
101107func (b * Builder ) Prepare (raws ... interface {}) ([]string , []string , error ) {
@@ -221,6 +227,8 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
221227
222228 var instanceStep multistep.Step
223229
230+ skipTerminationWait := shouldSkipSourceInstanceTerminationWait (& b .config )
231+
224232 if b .config .IsSpotInstance () {
225233 instanceStep = & awscommon.StepRunSpotInstance {
226234 PollingConfig : b .config .PollingConfig ,
@@ -296,6 +304,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
296304 UserDataFile : b .config .UserDataFile ,
297305 VolumeTags : b .config .VolumeRunTags ,
298306 NoEphemeral : b .config .NoEphemeral ,
307+ SkipTerminationWait : skipTerminationWait ,
299308 }
300309 }
301310
@@ -400,10 +409,12 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
400409 PollingConfig : b .config .PollingConfig ,
401410 Skip : b .config .IsSpotInstance (),
402411 DisableStopInstance : b .config .DisableStopInstance ,
412+ AMISkipCreateImage : b .config .AMISkipCreateImage ,
403413 },
404414 & awscommon.StepModifyEBSBackedInstance {
405415 EnableAMISriovNetSupport : b .config .AMISriovNetSupport ,
406416 EnableAMIENASupport : b .config .AMIENASupport ,
417+ AMISkipCreateImage : b .config .AMISkipCreateImage ,
407418 },
408419 & awscommon.StepDeregisterAMI {
409420 AccessConfig : & b .config .AccessConfig ,
0 commit comments