2018-01-12 19:06:03 -05:00
|
|
|
package classic
|
|
|
|
|
|
|
|
import (
|
2018-01-19 18:37:06 -05:00
|
|
|
"fmt"
|
2018-01-16 17:28:24 -05:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
2018-01-12 19:06:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stepCreateIPReservation struct{}
|
|
|
|
|
|
|
|
func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
ui.Say("Creating IP reservation...")
|
2018-01-19 18:37:06 -05:00
|
|
|
config := state.Get("config").(*Config)
|
2018-01-17 16:07:41 -05:00
|
|
|
client := state.Get("client").(*compute.ComputeClient)
|
2018-01-16 17:28:24 -05:00
|
|
|
iprClient := client.IPReservations()
|
|
|
|
// TODO: add optional Name and Tags
|
2018-01-17 16:07:41 -05:00
|
|
|
IPInput := &compute.CreateIPReservationInput{
|
2018-01-16 17:28:24 -05:00
|
|
|
ParentPool: compute.PublicReservationPool,
|
|
|
|
Permanent: true,
|
2018-01-19 18:37:06 -05:00
|
|
|
Name: fmt.Sprintf("ipres_%s", config.ImageName),
|
2018-01-16 17:28:24 -05:00
|
|
|
}
|
2018-01-17 16:07:41 -05:00
|
|
|
ipRes, err := iprClient.CreateIPReservation(IPInput)
|
2018-01-16 17:28:24 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error creating IP Reservation: %s", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2018-01-16 19:55:39 -05:00
|
|
|
state.Put("instance_ip", ipRes.IP)
|
2018-01-16 17:28:24 -05:00
|
|
|
log.Printf("debug: ipRes is %#v", ipRes)
|
|
|
|
return multistep.ActionContinue
|
2018-01-12 19:06:03 -05:00
|
|
|
}
|
2018-01-17 16:07:41 -05:00
|
|
|
|
|
|
|
func (s *stepCreateIPReservation) Cleanup(state multistep.StateBag) {
|
|
|
|
// Nothing to do
|
|
|
|
}
|