2016-04-14 20:29:27 -04:00
|
|
|
package triton
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2016-04-14 20:29:27 -04:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2016-04-14 20:29:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// StepDeleteMachine deletes the machine with the ID specified in state["machine"]
|
|
|
|
type StepDeleteMachine struct{}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepDeleteMachine) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2016-04-14 20:29:27 -04:00
|
|
|
driver := state.Get("driver").(Driver)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2016-04-14 20:29:27 -04:00
|
|
|
|
|
|
|
machineId := state.Get("machine").(string)
|
|
|
|
|
|
|
|
ui.Say("Deleting source machine...")
|
|
|
|
err := driver.DeleteMachine(machineId)
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Problem deleting source machine: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say("Waiting for source machine to be deleted...")
|
|
|
|
err = driver.WaitForMachineDeletion(machineId, 10*time.Minute)
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Problem waiting for source machine to be deleted: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
state.Put("machine", "")
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepDeleteMachine) Cleanup(state multistep.StateBag) {
|
|
|
|
// No clean up to do here...
|
|
|
|
}
|