github.phpd.cn/hashicorp/packer@v1.3.2/builder/triton/step_delete_machine.go (about) 1 package triton 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "github.com/hashicorp/packer/helper/multistep" 9 "github.com/hashicorp/packer/packer" 10 ) 11 12 // StepDeleteMachine deletes the machine with the ID specified in state["machine"] 13 type StepDeleteMachine struct{} 14 15 func (s *StepDeleteMachine) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 16 driver := state.Get("driver").(Driver) 17 ui := state.Get("ui").(packer.Ui) 18 19 machineId := state.Get("machine").(string) 20 21 ui.Say("Deleting source machine...") 22 err := driver.DeleteMachine(machineId) 23 if err != nil { 24 state.Put("error", fmt.Errorf("Problem deleting source machine: %s", err)) 25 return multistep.ActionHalt 26 } 27 28 ui.Say("Waiting for source machine to be deleted...") 29 err = driver.WaitForMachineDeletion(machineId, 10*time.Minute) 30 if err != nil { 31 state.Put("error", fmt.Errorf("Problem waiting for source machine to be deleted: %s", err)) 32 return multistep.ActionHalt 33 } 34 35 state.Put("machine", "") 36 37 return multistep.ActionContinue 38 } 39 40 func (s *StepDeleteMachine) Cleanup(state multistep.StateBag) { 41 // No clean up to do here... 42 }