2018-05-24 13:47:37 -04:00
|
|
|
package oci
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/helper/communicator"
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2018-05-24 13:47:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepGetDefaultCredentials struct {
|
|
|
|
Debug bool
|
|
|
|
Comm *communicator.Config
|
|
|
|
BuildName string
|
|
|
|
}
|
|
|
|
|
2018-06-26 05:05:56 -04:00
|
|
|
func (s *stepGetDefaultCredentials) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2018-05-24 13:47:37 -04:00
|
|
|
var (
|
|
|
|
driver = state.Get("driver").(*driverOCI)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui = state.Get("ui").(packersdk.Ui)
|
2018-05-24 13:47:37 -04:00
|
|
|
id = state.Get("instance_id").(string)
|
|
|
|
)
|
|
|
|
|
|
|
|
// Skip if we're not using winrm
|
|
|
|
if s.Comm.Type != "winrm" {
|
|
|
|
log.Printf("[INFO] Not using winrm communicator, skipping get password...")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we already have a password, skip it
|
|
|
|
if s.Comm.WinRMPassword != "" {
|
|
|
|
ui.Say("Skipping waiting for password since WinRM password set...")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2018-06-26 05:05:56 -04:00
|
|
|
username, password, err := driver.GetInstanceInitialCredentials(ctx, id)
|
2018-05-24 13:47:37 -04:00
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("Error getting instance's credentials: %s", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
s.Comm.WinRMPassword = password
|
|
|
|
s.Comm.WinRMUser = username
|
|
|
|
|
|
|
|
if s.Debug {
|
|
|
|
ui.Message(fmt.Sprintf(
|
|
|
|
"[DEBUG] (OCI default credentials): Credentials (since debug is enabled): %s", password))
|
|
|
|
}
|
|
|
|
|
|
|
|
// store so that we can access this later during provisioning
|
2019-07-11 15:10:57 -04:00
|
|
|
state.Put("winrm_password", s.Comm.WinRMPassword)
|
2020-11-19 17:03:11 -05:00
|
|
|
packersdk.LogSecretFilter.Set(s.Comm.WinRMPassword)
|
2018-05-24 13:47:37 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepGetDefaultCredentials) Cleanup(state multistep.StateBag) {
|
|
|
|
// no cleanup
|
|
|
|
}
|