generated from hashicorp/packer-plugin-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup VM in case of a failure (#120)
* Cleanup VM in case of a failure * Extracted cleanup in a separate step * Improved message
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package tart | ||
|
||
import ( | ||
"context" | ||
"github.com/hashicorp/packer-plugin-sdk/multistep" | ||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer" | ||
) | ||
|
||
type stepCleanVM struct{} | ||
|
||
func (s *stepCleanVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { | ||
return multistep.ActionContinue | ||
} | ||
|
||
func (s *stepCleanVM) Cleanup(state multistep.StateBag) { | ||
config := state.Get("config").(*Config) | ||
ui := state.Get("ui").(packersdk.Ui) | ||
|
||
_, cancelled := state.GetOk(multistep.StateCancelled) | ||
_, halted := state.GetOk(multistep.StateHalted) | ||
if cancelled || halted { | ||
ui.Say("Cleaning up virtual machine...") | ||
cmdArgs := []string{"delete", config.VMName} | ||
_, _ = TartExec(context.Background(), cmdArgs...) | ||
} | ||
} |