Skip to content

Make EBS source termination wait optional - #683

Open
FocalChord wants to merge 1 commit into
hashicorp:mainfrom
FocalChord:optional-source-termination-wait
Open

Make EBS source termination wait optional#683
FocalChord wants to merge 1 commit into
hashicorp:mainfrom
FocalChord:optional-source-termination-wait

Conversation

@FocalChord

Copy link
Copy Markdown

Description

This PR adds an Amazon EBS builder option named skip_source_instance_termination_wait.

When the option is false, behavior is unchanged. Packer still waits for EC2 to report the source instance as terminated.

When the option is true, Packer returns from source instance cleanup after TerminateInstances succeeds. This keeps the choice explicit and separate from skip_create_ami.

This PR does not change AMI creation or AMI preparation behavior.

Resolved Issues

Closes #682

Evidence

The direct EC2 data I saw suggests the final source instance state can take much longer on bare metal instances than the API acceptance of termination.

  1. c5.large reached terminated in about one minute after TerminateInstances was accepted.
  2. c5.metal remained shutting-down for more than 19 minutes before later reaching terminated.
  3. A minimal local Packer run on c5.metal saw EC2 accept source instance termination around one second after Packer requested it.

Validation

  1. go test ./builder/common ./common ./builder/ebs
  2. Local plugin build completed
  3. Git whitespace check passed

Rollback Plan

Revert this change.

Changes to Security Controls

No. This does not change access controls, encryption, or logging.

@FocalChord
FocalChord requested a review from a team as a code owner June 15, 2026 08:02
@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@FocalChord

Copy link
Copy Markdown
Author

Hi, I signed the CLA but unsure why it hasn't gone through yet.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in Amazon EBS builder setting to skip waiting for the source EC2 instance to reach the final terminated state during cleanup, addressing cases where termination state transitions can take a long time (e.g., some bare metal instances).

Changes:

  • Adds skip_source_instance_termination_wait to the EBS builder config, HCL2 spec, and documentation.
  • Updates source-instance cleanup steps to optionally skip the final “wait until terminated” polling.
  • Adds unit tests to ensure the new option is accepted by Prepare and appears in the HCL2 spec.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs-partials/builder/ebs/Config-not-required.mdx Documents the new skip_source_instance_termination_wait option.
common/step_run_source_instance.go Adds a flag to skip the final termination wait in the v2 EC2 source-instance cleanup step.
builder/common/step_run_source_instance.go Adds the same skip-wait flag to the v1 EC2 source-instance cleanup step.
builder/ebs/builder.hcl2spec.go Exposes the new option in the generated HCL2 decoding spec.
builder/ebs/builder.go Adds the config field and plumbs it into the non-spot source-instance step.
builder/ebs/builder_test.go Tests that the option is accepted by Prepare and present in the HCL2 spec map.
Files not reviewed (1)
  • builder/ebs/builder.hcl2spec.go: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread builder/ebs/builder.go
Comment on lines 300 to 305
UserData: b.config.UserData,
UserDataFile: b.config.UserDataFile,
VolumeTags: b.config.VolumeRunTags,
NoEphemeral: b.config.NoEphemeral,
SkipSourceInstanceTerminationWait: b.config.SkipSourceInstanceTerminationWait,
}
Comment on lines +497 to 504
if s.SkipSourceInstanceTerminationWait {
ui.Say("skip_source_instance_termination_wait was set; skipping final source instance termination wait")
return
}

if err := s.PollingConfig.WaitUntilInstanceTerminated(ctx, ec2Client, s.instanceId); err != nil {
ui.Error(err.Error())
}
Comment on lines +492 to 499
if s.SkipSourceInstanceTerminationWait {
ui.Say("skip_source_instance_termination_wait was set; skipping final source instance termination wait")
return
}

if err := s.PollingConfig.WaitUntilInstanceTerminated(aws.BackgroundContext(), ec2conn, s.instanceId); err != nil {
ui.Error(err.Error())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EBS source instance termination wait can dominate cleanup

3 participants