Use `PublicIp` for communicator

This commit is contained in:
유성덕 2018-01-29 22:07:32 +09:00
parent e57a8161e0
commit 6b40c726e0
3 changed files with 6 additions and 15 deletions

View File

@ -47,8 +47,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
NewStepGetRootPassword(conn, ui),
NewStepCreatePublicIPInstance(conn, ui, b.config),
&communicator.StepConnectSSH{
Config: &b.config.Comm,
Host: SSHHost,
Config: &b.config.Comm,
Host: func(stateBag multistep.StateBag) (string, error) {
return stateBag.Get("PublicIP").(string), nil
},
SSHConfig: SSHConfig(b.config.Comm.SSHUsername),
},
&common.StepProvision{},
@ -68,7 +70,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&communicator.StepConnectWinRM{
Config: &b.config.Comm,
Host: func(stateBag multistep.StateBag) (string, error) {
return stateBag.Get("WinRMHost").(string), nil
return stateBag.Get("PublicIP").(string), nil
},
WinRMConfig: func(state multistep.StateBag) (*communicator.WinRMConfig, error) {
return &communicator.WinRMConfig{

View File

@ -6,11 +6,6 @@ import (
"golang.org/x/crypto/ssh"
)
func SSHHost(state multistep.StateBag) (string, error) {
host := state.Get("SSHHost").(string)
return host, nil
}
// SSHConfig returns a function that can be used for the SSH communicator
// config for connecting to the specified host via SSH
func SSHConfig(username string) func(multistep.StateBag) (*ssh.ClientConfig, error) {

View File

@ -91,13 +91,7 @@ func (s *StepCreatePublicIPInstance) Run(state multistep.StateBag) multistep.Ste
publicIPInstance, err := s.CreatePublicIPInstance(serverInstanceNo)
if err == nil {
switch s.Config.Comm.Type {
case "ssh":
state.Put("SSHHost", publicIPInstance.PublicIP)
case "winrm":
state.Put("WinRMHost", publicIPInstance.PublicIP)
}
state.Put("PublicIP", publicIPInstance.PublicIP)
state.Put("PublicIPInstance", publicIPInstance)
}