Make EBS source termination wait optional - #683
Conversation
|
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. |
|
Hi, I signed the CLA but unsure why it hasn't gone through yet. |
There was a problem hiding this comment.
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_waitto 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
Prepareand 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.
| UserData: b.config.UserData, | ||
| UserDataFile: b.config.UserDataFile, | ||
| VolumeTags: b.config.VolumeRunTags, | ||
| NoEphemeral: b.config.NoEphemeral, | ||
| SkipSourceInstanceTerminationWait: b.config.SkipSourceInstanceTerminationWait, | ||
| } |
| 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()) | ||
| } |
| 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()) | ||
| } |
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
TerminateInstancessucceeds. This keeps the choice explicit and separate fromskip_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.
c5.largereachedterminatedin about one minute afterTerminateInstanceswas accepted.c5.metalremainedshutting-downfor more than 19 minutes before later reachingterminated.c5.metalsaw EC2 accept source instance termination around one second after Packer requested it.Validation
go test ./builder/common ./common ./builder/ebsRollback Plan
Revert this change.
Changes to Security Controls
No. This does not change access controls, encryption, or logging.