diff --git a/builder/ncloud/builder.go b/builder/ncloud/builder.go index 9e53edcf8..9748a848a 100644 --- a/builder/ncloud/builder.go +++ b/builder/ncloud/builder.go @@ -44,7 +44,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe NewStepCreateLoginKey(conn, ui), NewStepCreateServerInstance(conn, ui, b.config), NewStepCreateBlockStorageInstance(conn, ui, b.config), - NewStepGetRootPassword(conn, ui), + NewStepGetRootPassword(conn, ui, b.config), NewStepCreatePublicIPInstance(conn, ui, b.config), &communicator.StepConnectSSH{ Config: &b.config.Comm, @@ -68,7 +68,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe NewStepCreateLoginKey(conn, ui), NewStepCreateServerInstance(conn, ui, b.config), NewStepCreateBlockStorageInstance(conn, ui, b.config), - NewStepGetRootPassword(conn, ui), + NewStepGetRootPassword(conn, ui, b.config), NewStepCreatePublicIPInstance(conn, ui, b.config), &communicator.StepConnectWinRM{ Config: &b.config.Comm, @@ -78,7 +78,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe WinRMConfig: func(state multistep.StateBag) (*communicator.WinRMConfig, error) { return &communicator.WinRMConfig{ Username: b.config.Comm.WinRMUser, - Password: state.Get("Password").(string), + Password: b.config.Comm.WinRMPassword, }, nil }, }, diff --git a/builder/ncloud/config.go b/builder/ncloud/config.go index c8c1374bb..e16f480c0 100644 --- a/builder/ncloud/config.go +++ b/builder/ncloud/config.go @@ -105,7 +105,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { errs = packer.MultiErrorAppend(errs, errors.New("If user_data field is set, length of UserData should be max 21847")) } - if c.Comm.Type == "wrinrm" && c.AccessControlGroupConfigurationNo == "" { + if c.Comm.Type == "winrm" && c.AccessControlGroupConfigurationNo == "" { errs = packer.MultiErrorAppend(errs, errors.New("If Communicator is winrm, access_control_group_configuration_no is required")) } diff --git a/builder/ncloud/step_get_rootpassword.go b/builder/ncloud/step_get_rootpassword.go index 051eb386b..a57058dc6 100644 --- a/builder/ncloud/step_get_rootpassword.go +++ b/builder/ncloud/step_get_rootpassword.go @@ -14,13 +14,15 @@ type StepGetRootPassword struct { GetRootPassword func(serverInstanceNo string, privateKey string) (string, error) Say func(message string) Error func(e error) + Config *Config } -func NewStepGetRootPassword(conn *ncloud.Conn, ui packer.Ui) *StepGetRootPassword { +func NewStepGetRootPassword(conn *ncloud.Conn, ui packer.Ui, config *Config) *StepGetRootPassword { var step = &StepGetRootPassword{ - Conn: conn, - Say: func(message string) { ui.Say(message) }, - Error: func(e error) { ui.Error(e.Error()) }, + Conn: conn, + Say: func(message string) { ui.Say(message) }, + Error: func(e error) { ui.Error(e.Error()) }, + Config: config, } step.GetRootPassword = step.getRootPassword @@ -51,7 +53,11 @@ func (s *StepGetRootPassword) Run(_ context.Context, state multistep.StateBag) m rootPassword, err := s.GetRootPassword(serverInstanceNo, loginKey.PrivateKey) - state.Put("Password", rootPassword) + if s.Config.Comm.Type == "ssh" { + s.Config.Comm.SSHPassword = rootPassword + } else if s.Config.Comm.Type == "winrm" { + s.Config.Comm.WinRMPassword = rootPassword + } return processStepResult(err, s.Error, state) } diff --git a/builder/ncloud/step_get_rootpassword_test.go b/builder/ncloud/step_get_rootpassword_test.go index 0c93229bd..c048a8144 100644 --- a/builder/ncloud/step_get_rootpassword_test.go +++ b/builder/ncloud/step_get_rootpassword_test.go @@ -13,6 +13,7 @@ func TestStepGetRootPasswordShouldFailIfOperationGetRootPasswordFails(t *testing GetRootPassword: func(string, string) (string, error) { return "", fmt.Errorf("!! Unit Test FAIL !!") }, Say: func(message string) {}, Error: func(e error) {}, + Config: &Config{}, } stateBag := DeleteTestStateBagStepGetRootPassword() @@ -33,6 +34,7 @@ func TestStepGetRootPasswordShouldPassIfOperationGetRootPasswordPasses(t *testin GetRootPassword: func(string, string) (string, error) { return "a", nil }, Say: func(message string) {}, Error: func(e error) {}, + Config: &Config{}, } stateBag := DeleteTestStateBagStepGetRootPassword()