packer-cn/builder/oracle/classic/step_terminate_pv_master.go

47 lines
1.2 KiB
Go
Raw Normal View History

2018-09-06 01:44:31 -04:00
package classic
import (
"context"
"fmt"
"github.com/hashicorp/go-oracle-terraform/compute"
2020-11-17 19:31:03 -05:00
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
2018-09-06 01:44:31 -04:00
)
type stepTerminatePVMaster struct {
}
func (s *stepTerminatePVMaster) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2018-09-06 01:44:31 -04:00
// get variables from state
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) {
}