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

43 lines
1.2 KiB
Go
Raw Normal View History

2018-01-12 19:06:03 -05:00
package classic
import (
2018-01-25 17:43:55 -05:00
"context"
"fmt"
"log"
"github.com/hashicorp/go-oracle-terraform/compute"
2018-01-25 17:45:09 -05:00
"github.com/hashicorp/packer/helper/multistep"
2018-01-12 19:06:03 -05:00
"github.com/hashicorp/packer/packer"
)
type stepCreateIPReservation struct{}
2018-01-25 17:42:39 -05:00
func (s *stepCreateIPReservation) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
2018-01-12 19:06:03 -05:00
ui := state.Get("ui").(packer.Ui)
ui.Say("Creating IP reservation...")
config := state.Get("config").(*Config)
2018-01-17 16:07:41 -05:00
client := state.Get("client").(*compute.ComputeClient)
iprClient := client.IPReservations()
// TODO: add optional Name and Tags
2018-01-17 16:07:41 -05:00
IPInput := &compute.CreateIPReservationInput{
ParentPool: compute.PublicReservationPool,
Permanent: true,
Name: fmt.Sprintf("ipres_%s", config.ImageName),
}
2018-01-17 16:07:41 -05:00
ipRes, err := iprClient.CreateIPReservation(IPInput)
2018-01-23 17:16:51 -05:00
if err != nil {
2018-01-23 17:16:51 -05:00
err := fmt.Errorf("Error creating IP Reservation: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
2018-01-16 19:55:39 -05:00
state.Put("instance_ip", ipRes.IP)
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) {
2018-01-23 17:16:51 -05:00
// TODO: delete ip reservation
2018-01-17 16:07:41 -05:00
}