fix: build cleanup and terminate on failure - #22
Merged
Conversation
* Some failures were leaving behind AMIs (name prefaced by `ami-builder-`) that weren't getting cleaned up by the janitor. Added cleanup-related tags so the janitor would clean up failures. * Some failures were shutting down by leaving the instance in a "stopped" state, with the EBS volume still active, meaning we were getting charged for EBS. This switches shutdown mode to "terminate," which will delete the EBS volume on failure (just as on success). Assisted-by: Codex.app:GPT-5.6-Sol
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves cleanup behavior for failed AMI builds by (1) ensuring failed-build artifacts are easier to identify/tag for automated cleanup and (2) changing the Packer instance shutdown behavior to terminate (to avoid leaving stopped instances/volumes behind on failure).
Changes:
- Add failed-build AMI detection (
ami-builder-name tag prefix) and emit a warning whenauto-deletecleans these up. - Update Packer
amazon-ebsconfig toshutdown_behavior = "terminate"and expandrun_tagsto include the merged cleanup tag set. - Extend CLI tests to cover failed-build detection and the new
auto-deletewarning behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cli/test_ami_cli.py | Adds test coverage for failed-build name-prefix detection and auto-delete warning/deletion behavior. |
| cli/ami_cli.py | Introduces failed-build AMI detection and warning output during auto-delete. |
| build-ami.pkr.hcl | Switches shutdown behavior to terminate and merges standard tags into run_tags to improve cleanup/traceability on failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ami-builder-) that weren't getting cleaned up by the janitor. Added cleanup-related tags so the janitor would clean up failures.Assisted-by: Codex.app:GPT-5.6-Sol