2017-09-12 11:30:39 -04:00
|
|
|
package oci
|
2017-02-13 05:35:14 -05:00
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2017-02-13 05:35:14 -05:00
|
|
|
"fmt"
|
|
|
|
|
2017-04-07 06:20:33 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2017-02-13 05:35:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepInstanceInfo struct{}
|
|
|
|
|
2018-06-26 05:05:56 -04:00
|
|
|
func (s *stepInstanceInfo) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2017-02-13 05:35:14 -05:00
|
|
|
var (
|
|
|
|
driver = state.Get("driver").(Driver)
|
|
|
|
ui = state.Get("ui").(packer.Ui)
|
|
|
|
id = state.Get("instance_id").(string)
|
|
|
|
)
|
|
|
|
|
2018-06-26 05:05:56 -04:00
|
|
|
ip, err := driver.GetInstanceIP(ctx, id)
|
2017-02-13 05:35:14 -05:00
|
|
|
if err != nil {
|
2018-03-22 04:08:25 -04:00
|
|
|
err = fmt.Errorf("Error getting instance's IP: %s", err)
|
2017-08-02 06:53:14 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
state.Put("error", err)
|
2017-02-13 05:35:14 -05:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
state.Put("instance_ip", ip)
|
|
|
|
|
2018-03-22 04:08:25 -04:00
|
|
|
ui.Say(fmt.Sprintf("Instance has IP: %s.", ip))
|
2017-02-13 05:35:14 -05:00
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepInstanceInfo) Cleanup(state multistep.StateBag) {
|
|
|
|
// no cleanup
|
|
|
|
}
|