2018-01-12 19:06:03 -05:00
|
|
|
package classic
|
|
|
|
|
|
|
|
import (
|
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-16 17:28:24 -05:00
|
|
|
client := state.Get("client", client).(*compute.ComputeClient)
|
|
|
|
iprClient := client.IPReservations()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error getting IPReservations Client: %s", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
// TODO: add optional Name and Tags
|
|
|
|
IPInput := &iprClient.CreateIPReservationInput{
|
|
|
|
ParentPool: compute.PublicReservationPool,
|
|
|
|
Permanent: true,
|
|
|
|
}
|
|
|
|
ipRes, err := iprClient.CreateIPReservation(createIPReservation)
|
|
|
|
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
|
|
|
}
|