2018-01-16 19:55:39 -05:00
|
|
|
package classic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stepSnapshot struct{}
|
|
|
|
|
|
|
|
func (s *stepSnapshot) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
// get variables from state
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
ui.Say("Creating Snapshot...")
|
2018-01-17 19:25:38 -05:00
|
|
|
config := state.Get("config").(*Config)
|
2018-01-16 19:55:39 -05:00
|
|
|
client := state.Get("client").(*compute.ComputeClient)
|
|
|
|
instanceID := state.Get("instance_id").(string)
|
|
|
|
|
|
|
|
// get instances client
|
2018-01-17 16:07:41 -05:00
|
|
|
snapshotClient := client.Snapshots()
|
2018-01-16 19:55:39 -05:00
|
|
|
|
|
|
|
// Instances Input
|
2018-01-17 16:07:41 -05:00
|
|
|
snapshotInput := &compute.CreateSnapshotInput{
|
2018-01-16 19:55:39 -05:00
|
|
|
Instance: instanceID,
|
|
|
|
MachineImage: config.ImageName,
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:07:41 -05:00
|
|
|
snap, err := snapshotClient.CreateSnapshot(snapshotInput)
|
2018-01-16 19:55:39 -05:00
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("Problem creating snapshot: %s", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Created snapshot (%s).", snap.Name))
|
2018-01-17 16:07:41 -05:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepSnapshot) Cleanup(state multistep.StateBag) {
|
|
|
|
// Nothing to do
|
2018-01-16 19:55:39 -05:00
|
|
|
}
|