2018-09-06 01:44:31 -04:00
|
|
|
package classic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2018-09-06 01:44:31 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepTerminatePVMaster struct {
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *stepTerminatePVMaster) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2018-09-06 01:44:31 -04:00
|
|
|
// get variables from state
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2018-09-06 01:44:31 -04:00
|
|
|
ui.Say("Deleting master Instance...")
|
|
|
|
|
2018-10-24 17:08:11 -04:00
|
|
|
client := state.Get("client").(*compute.Client)
|
2018-09-06 01:44:31 -04:00
|
|
|
instanceInfo := state.Get("master_instance_info").(*compute.InstanceInfo)
|
|
|
|
|
|
|
|
// get instances client
|
|
|
|
instanceClient := client.Instances()
|
|
|
|
|
|
|
|
// Instances Input
|
|
|
|
input := &compute.DeleteInstanceInput{
|
|
|
|
Name: instanceInfo.Name,
|
|
|
|
ID: instanceInfo.ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := instanceClient.DeleteInstance(input)
|
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("Problem creating instance: %s", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Message(fmt.Sprintf("Deleted master instance: %s.", instanceInfo.ID))
|
2018-09-06 03:05:47 -04:00
|
|
|
state.Put("master_instance_deleted", true)
|
2018-09-06 01:44:31 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepTerminatePVMaster) Cleanup(state multistep.StateBag) {
|
|
|
|
}
|