diff --git a/packer/builder/azure/config.go b/packer/builder/azure/config.go index 645dd50..75eb885 100644 --- a/packer/builder/azure/config.go +++ b/packer/builder/azure/config.go @@ -44,6 +44,7 @@ type Config struct { tmpServiceName string tmpContainerName string userImageName string + SSHPrivateIp bool `mapstructure:"ssh_private_ip"` Comm communicator.Config `mapstructure:",squash"` diff --git a/packer/builder/azure/config_test.go b/packer/builder/azure/config_test.go index f468ac9..c0aae15 100644 --- a/packer/builder/azure/config_test.go +++ b/packer/builder/azure/config_test.go @@ -21,6 +21,7 @@ func getDefaultTestConfig(publishSettingsFileName string) map[string]interface{} "location": "Central US", "instance_size": "Large", "user_image_label": "boo", + "use_private_ip": false, } } diff --git a/packer/builder/azure/step_poll_status.go b/packer/builder/azure/step_poll_status.go index 9b8631e..0895908 100644 --- a/packer/builder/azure/step_poll_status.go +++ b/packer/builder/azure/step_poll_status.go @@ -28,6 +28,7 @@ func (s *StepPollStatus) Run(state multistep.StateBag) multistep.StepAction { client := state.Get(constants.RequestManager).(management.Client) vmc := vm.NewClient(client) ui := state.Get(constants.Ui).(packer.Ui) + config := state.Get(constants.Config).(*Config) errorMsg := "Error polling temporary Azure VM is ready: %s" @@ -101,18 +102,21 @@ func (s *StepPollStatus) Run(state multistep.StateBag) multistep.StepAction { log.Println("s.OSType = " + s.OSType) if s.OSType == constants.Target_Linux { - endpoints := deployment.RoleInstanceList[0].InstanceEndpoints - if len(endpoints) == 0 { - err := fmt.Errorf(errorMsg, "deployment.RoleInstanceList[0].InstanceEndpoints list is empty") - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt - } - - vip := endpoints[0].Vip - state.Put(constants.SSHHost, vip) - - ui.Message("VM Endpoint: " + vip) + var ip string + if config.SSHPrivateIp { + ip = deployment.RoleInstanceList[0].IPAddress + } else { + endpoints := deployment.RoleInstanceList[0].InstanceEndpoints + if len(endpoints) == 0 { + err := fmt.Errorf(errorMsg, "deployment.RoleInstanceList[0].InstanceEndpoints list is empty") + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + ip = endpoints[0].Vip + } + state.Put(constants.SSHHost, ip) + ui.Message("VM Endpoint: " + ip) } roleList := deployment.RoleList