clean up instance

This commit is contained in:
Megan Marsh 2018-01-19 16:08:42 -08:00 committed by Matthew Hooker
parent 256382547b
commit f6c60aac78
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
1 changed files with 26 additions and 1 deletions

View File

@ -92,5 +92,30 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
} }
func (s *stepCreateInstance) Cleanup(state multistep.StateBag) { func (s *stepCreateInstance) Cleanup(state multistep.StateBag) {
// Nothing to do // terminate instance
ui := state.Get("ui").(packer.Ui)
client := state.Get("client").(*compute.ComputeClient)
imID := state.Get("instance_id").(string)
ui.Say(fmt.Sprintf("Terminating instance (%s)...", id))
instanceClient := client.Instances()
// Instances Input
input := &compute.DeleteInstanceInput{
Name: config.ImageName,
ID: imID,
}
instanceInfo, err := instanceClient.DeleteInstance(input)
if err != nil {
err = fmt.Errorf("Problem destroying instance: %s", err)
ui.Error(err.Error())
state.Put("error", err)
return
}
// TODO wait for instance state to change to deleted?
ui.Say("Terminated instance.")
return
} }