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

46 lines
1.1 KiB
Go
Raw Normal View History

2018-01-12 19:06:03 -05:00
package classic
import (
2018-01-12 19:18:55 -05:00
"fmt"
2018-01-16 19:55:39 -05:00
"github.com/hashicorp/go-oracle-terraform/compute"
2018-01-12 19:06:03 -05:00
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
)
2018-01-12 19:18:55 -05:00
type stepCreateInstance struct{}
2018-01-12 19:06:03 -05:00
2018-01-16 19:55:39 -05:00
func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction {
2018-01-12 19:48:35 -05:00
ui.Say("Creating Instance...")
2018-01-16 19:55:39 -05:00
// get variables from state
ui := state.Get("ui").(packer.Ui)
config := state.Get("config").(Config)
client := state.Get("client").(*compute.ComputeClient)
sshPublicKey := state.Get("publicKey").(string)
// get instances client
instanceClient := client.Instances()
// Instances Input
input := &compute.CreateInstanceInput{
Name: config.ImageName,
Shape: config.Shape,
ImageList: config.ImageList,
SSHKeys: []string{},
Attributes: map[string]interface{}{},
2018-01-12 19:51:59 -05:00
}
2018-01-16 19:55:39 -05:00
instanceInfo, err := instanceClient.CreateInstance(input)
2018-01-12 19:18:55 -05:00
if err != nil {
err = fmt.Errorf("Problem creating instance: %s", err)
ui.Error(err.Error())
state.Put("error", err)
return multistep.ActionHalt
}
2018-01-16 19:55:39 -05:00
state.Put("instance_id", instanceInfo.ID)
2018-01-12 19:18:55 -05:00
ui.Say(fmt.Sprintf("Created instance (%s).", instanceID))
2018-01-12 19:06:03 -05:00
}