packer-cn/builder/oracle/oci/step_instance_info.go

38 lines
839 B
Go
Raw Normal View History

package oci
import (
"context"
"fmt"
2020-11-17 19:31:03 -05:00
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
)
type stepInstanceInfo struct{}
2018-06-26 05:05:56 -04:00
func (s *stepInstanceInfo) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
var (
driver = state.Get("driver").(Driver)
ui = state.Get("ui").(packersdk.Ui)
id = state.Get("instance_id").(string)
)
2018-06-26 05:05:56 -04:00
ip, err := driver.GetInstanceIP(ctx, id)
if err != nil {
err = fmt.Errorf("Error getting instance's IP: %s", err)
ui.Error(err.Error())
state.Put("error", err)
return multistep.ActionHalt
}
state.Put("instance_ip", ip)
ui.Say(fmt.Sprintf("Instance has IP: %s.", ip))
return multistep.ActionContinue
}
func (s *stepInstanceInfo) Cleanup(state multistep.StateBag) {
// no cleanup
}